Issue with HTTP request in Objective C
Iam trying to submit values to an external DB using http request
My code is below
NSString *开发者_StackOverflowpost =[NSString stringWithFormat:@"user=%@&child=%@&content=%@",userId,childId, crackContent.text];
responseData = [[NSMutableData data] retain];
NSString *hostStr = @"http://myhost.com/addItem.php?";
post = [utilityObj getEncodedUrl:post];
hostStr = [hostStr stringByAppendingString:post];
NSLog(hostStr);
NSLog(hostStr);
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:hostStr]];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
My issue is that if any space contains any of the parameter it will not submitted, otherwise it is successfully submitted.
Help is highly appreciated.
You may get the parameter encoded before send.
NSString* escapedUrlString =
[unescapedString stringByAddingPercentEscapesUsingEncoding:
NSASCIIStringEncoding];
Alternative
NSString * escapedUrlString = (NSString *)CFURLCreateStringByAddingPercentEscapes(
NULL,
(CFStringRef)unescapedString,
NULL,
(CFStringRef)@"!*'\"();:@&=+$,/?%#[]% ",
kCFStringEncodingUTF8 );
精彩评论