iPhone URL encoding Problem

后端 未结 2 1269
轮回少年
轮回少年 2021-01-06 07:06

Have a slight problem. Trying to post XML to a server. To do this, I have to encode the XML string in URL format.

NSString *encodedString = [NSString strin         


        
相关标签:
2条回答
  • 2021-01-06 07:55

    This should solve your problem:

      NSString * encodedString = (NSString *)CFURLCreateStringByAddingPercentEscapes(
        NULL,
        (CFStringRef)unencodedString,
        NULL,
        (CFStringRef)@"!*'();:@&=+$,/?%#[]",
        kCFStringEncodingUTF8 );
    

    Source

    0 讨论(0)
  • 2021-01-06 07:57

    You can try this. I found this helpful.

    NSString *sampleUrl = @"http://www.google.com/search.jsp?params=Java Developer";
    NSString* encodedUrl = [sampleUrl stringByAddingPercentEscapesUsingEncoding:
     NSASCIIStringEncoding];
    
    0 讨论(0)
提交回复
热议问题