简体   繁体   English

iPhone URL编码问题

[英]iPhone URL encoding Problem

Have a slight problem. 有一点问题。 Trying to post XML to a server. 试图将XML发布到服务器。 To do this, I have to encode the XML string in URL format. 为此,我必须以URL格式对XML字符串进行编码。

NSString *encodedString = [NSString stringWithFormat:@"xmlValue=%@",[post stringByAddingPercentEscapesUsingEncoding: NSASCIIStringEncoding]];

That's what I have and it works for all the characters EXCEPT the '='. 这就是我所拥有的,除了'='之外,它适用于所有角色。 This does not get converted to %3D. 这不会转换为%3D。 Has anyone else ever had this problem before? 有没有其他人曾经遇到过这个问题? Am I specifying the wrong encoding type? 我指定了错误的编码类型吗? I have tried "NSUTF8StringEncoding" as well. 我也试过“NSUTF8StringEncoding”。

This is a little piece of the XML string: 这是XML字符串的一小部分:

@"<xml-service application=\"broadcast\" type=\"REQUEST\"><identity token=\"xxxxxxxx\".....

Any help would be appreciated! 任何帮助,将不胜感激! Thanks 谢谢

This should solve your problem: 这应该可以解决您的问题:

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

Source 资源

You can try this. 你可以试试这个。 I found this helpful. 我觉得这很有帮助。

NSString *sampleUrl = @"http://www.google.com/search.jsp?params=Java Developer";
NSString* encodedUrl = [sampleUrl stringByAddingPercentEscapesUsingEncoding:
 NSASCIIStringEncoding];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM