Для AFNetworking 3.0 ( iOS9 или более )
NSString *strURL = @"https://exampleWeb.com/webserviceOBJ";
NSDictionary *dictParamiters = @{@"user[height]": height,@"user[weight]": weight};
NSString *aStrParams = [self getFormDataStringWithDictParams:dictParamiters];
NSData *aData = [aStrParams dataUsingEncoding:NSUTF8StringEncoding];
NSMutableURLRequest *aRequest = [[NSMutableURLRequest alloc]initWithURL:[NSURL URLWithString:strURL]];
[aRequest setHTTPMethod:@"POST"];
[aRequest setHTTPBody:aData];
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:nil delegateQueue:nil];
[aRequest setHTTPBody:aData];
NSURLSessionDataTask *postDataTask = [session dataTaskWithRequest:aRequest completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
//
if (error ==nil) {
NSString *aStr = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"ResponseString:%@",aStr);
NSMutableDictionary *aMutDict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
dispatch_async(dispatch_get_main_queue(), ^{
completionBlock(aMutDict);
NSLog(@"responce:%@",aMutDict)
});
}
else
{
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"error:%@",error.locali)
});
}
}];
[postDataTask resume];
и Добавить
-(NSString *)getFormDataStringWithDictParams:(NSDictionary *)aDict
{
NSMutableString *aMutStr = [[NSMutableString alloc]initWithString:@""];
for (NSString *aKey in aDict.allKeys) {
[aMutStr appendFormat:@"%@=%@&",aKey,aDict[aKey]];
}
NSString *aStrParam;
if (aMutStr.length>2) {
aStrParam = [aMutStr substringWithRange:NSMakeRange(0, aMutStr.length-1)];
}
else
aStrParam = @"";
return aStrParam;
}