An easy solution for your problem that might work is not to use an application/x-www-urlformencoded
content type, but instead to use JSON. That is, specify application/json
as the value for the Content-Type
header in your HTTP request and send the parameters as JSON:
So, first create a JSON from your parameters:
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
NSDictionary* params = @{@"imageUrl": url, @"realName": name};
NSError* error;
NSData* jsonData = [NSJSONSerialization dataWithJSONObject:params options:0 error:&error];
Pass that JSON data as your request data.
Note:
Sending POST parameters as application/x-www-urlformencoded
requires properly encoded parameters. How to precent encode the parameters is likely the most wrongly answered question on SO, though many incorrectly encoded parameters will work anyway on most servers.
The definitive answer how to encode correctly is here:
The algorithm as specified by w3c.
I've put an implementation of the above algorithm in Objective-C based on Core Foundation elsewhere on SO, including a convenient method which converts a NSDictionary to a NSData object, properly percent encoded.
However, given the above specification, it should be easy to implement it yourself - without using Core Foundation or Foundation, and thus becoming dependent on that Core Foundation implementation, which may break that algorithm when Core Foundation changes.