iphone - 将Textview文本转换为post请求参数--iphone开发

标签 iphone cocoa cocoa-touch request

我想通过发布请求将我的 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/

相关文章:

ios - 写入流 iOS 时的自旋锁(仅在模拟器上)

objective-c - DCRoundSwitch 在使用 ARC 时给出 EXC_BAD_ACCESS

ios - 如何在 View Controller 时间轴中跳回两步?

iOS 7 问题 : viewDidDisappear not being called after viewWillDisappear

cocoa - 如何从 NSScriptCommand 子类的 PerformDefaultImplementation 返回对象列表?

cocoa - NSUnderlineStyle Single 是两个像素

ios - 验证UITextField不包含字母

ios - Present 时出现 UIImagePickerController 问题

iphone - Objective-C - NSNotificationCenter 放在哪里?

iphone - 从 AddressBook.framework 生成 vCard