I want to use AFNetworking for a HTTP Post method with some parameters and two values have the same parameter. I tried out:
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
NSDictionary *params = [NSDictionarydictionaryWithObjectsAndKeys: @"value1", @"param1", @"value2", @"param2", @"value3", @"param3", @"value4", @"param3", nil];
NSMutableURLRequest *request = [httpClient requestWithMethod:@"POST" path:@"/index.php" parameters:params];
I used Charles Proxy and figured out that the value4 was missing in my request.
Then I tried:
NSString *parameter = @"param1=value1¶m2=value2¶m3=value3¶m3=value4";
[request setHTTPBody:[parameter dataUsingEncoding:NSUTF8StringEncoding]];
And this worked.
Now I want to know if I am doing something wrong with AFNetworking or is this a bug of AFNetworking?
Your issue is not with AFNetworking but with NSDictionary. You cannot have two entries with the same key.
In this case it means:
should be replaced the following
Combining the two values for the one key.
Another way of combining arguments in one key is using a NSArray. For example: