Yes, you need to encode parameters explicitly.
It's relatively straightforward. Here's a extension to NSMutableURLRequest that I use which encodes a dictionary of strings as POST parameters.
@interface NSMutableURLRequest (WebServiceClient)
+ (NSString *) encodeFormPostParameters: (NSDictionary *) parameters;
- (void) setFormPostParameters: (NSDictionary *) parameters;
@end
@implementation NSMutableURLRequest (WebServiceClient)
+ (NSString *) encodeFormPostParameters: (NSDictionary *) parameters {
NSMutableString *formPostParams = [[[NSMutableString alloc] init] autorelease];
NSEnumerator *keys = [parameters keyEnumerator];
NSString *name = [keys nextObject];
while (nil != name) {
NSString *encodedValue = [((NSString *) CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef) [parameters objectForKey: name], NULL, CFSTR("=/:"), kCFStringEncodingUTF8)) autorelease];
[formPostParams appendString: name];
[formPostParams appendString: @"="];
[formPostParams appendString: encodedValue];
name = [keys nextObject];
if (nil != name) {
[formPostParams appendString: @"&"];
}
}
return formPostParams;
}
- (void) setFormPostParameters: (NSDictionary *) parameters {
NSString *formPostParams = [NSMutableURLRequest encodeFormPostParameters: parameters];
[self setHTTPBody: [formPostParams dataUsingEncoding: NSUTF8StringEncoding]];
[self setValue: @"application/x-www-form-urlencoded; charset=utf-8" forHTTPHeaderField: @"Content-Type"];
}
@end