xcode iPhone URL 编码问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3924871/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
iPhone URL encoding Problem
提问by gabaum10
Have a slight problem. Trying to post XML to a server. To do this, I have to encode the XML string in URL format.
有一点小问题。尝试将 XML 发布到服务器。为此,我必须以 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. Has anyone else ever had this problem before? Am I specifying the wrong encoding type? I have tried "NSUTF8StringEncoding" as well.
这就是我所拥有的,它适用于除“=”之外的所有字符。这不会转换为 %3D。有没有其他人遇到过这个问题?我是否指定了错误的编码类型?我也试过“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
任何帮助,将不胜感激!谢谢
回答by Ben
回答by Nishant
You can try this. I found this helpful.
你可以试试这个。我发现这很有帮助。
NSString *sampleUrl = @"http://www.google.com/search.jsp?params=Java Developer";
NSString* encodedUrl = [sampleUrl stringByAddingPercentEscapesUsingEncoding:
NSASCIIStringEncoding];