I am migrating from ASIHTTPRequest to AFNetworking and have run into an issue.
I am trying to hit an API with a request that overloads the post parameter. I was previously using ASIFormDataRequest for this and used this code to update 3 ids at the same time.
// ASIHTTPRequestCode
[request addPostValue:@"value1" forKey:@"id"];
[request addPostValue:@"value2" forKey:@"id"];
[request addPostValue:@"value3" forKey:@"id"];
Since AFNetworking uses an NSDictionary to store key value pairs, it doesn’t seem straight forward how to do this. Any ideas?
I can’t immediately see a direct way to do this with AFNetworking, but it is possible to do.
If you look at the code for
AFHTTPClient requestWithMethod, you’ll see this line, which is the one that sets up the request body to contain the parameters:Basically you could pass an empty dictionary to
requestWithMethodfor the parameters, then it returns, callrequest setHTTPBodyyourself, making up the query string yourself in a similar way to the wayAFQueryStringFromParametersWithEncodingdoes it.