开发者

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 );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜