我想通过发布请求将我的 TextView 内容传递到服务器,但我想我有编码问题。做|必须手动将空格转换为 + 或 %20 或者是否有 cocoa 或任何其他第三方支持的库?这……是小事吗?我在这个简单的步骤上坚持了几个小时! :)
最佳答案
看看如何在 http://www.rudis.net/content/2009/01/26/adding-percent-esacpes-cocoa 添加百分比转义的示例,引用作者的话:
One obvious way to do this is by calling NSString's
-(NSString*)stringByAddingPercentEscapesUsingEncoding:(NSStringEncoding)encoding
method. While this does a good job, it is not perfect and will miss things like "/", which may make some web services cry. The best way to do this encoding is to use:
CFStringRef CFURLCreateStringByAddingPercentEscapes (
CFAllocatorRef allocator,
CFStringRef originalString,
CFStringRef charactersToLeaveUnescaped,
CFStringRef legalURLCharactersToBeEscaped,
CFStringEncoding encoding
);
跳转后的示例代码(参见上面的链接)。
关于iphone - 将Textview文本转换为post请求参数--iphone开发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/994078/