Iphone ASIHTTPRequest中POST中的空正文
基本上,我发送的POST请求包含一个空数据体:Iphone ASIHTTPRequest中POST中的空正文,iphone,objective-c,asihttprequest,Iphone,Objective C,Asihttprequest,基本上,我发送的POST请求包含一个空数据体: ASIHTTPRequest *request [ASIHTTPRequest alloc] init]; [request setURL:[NSURL URLWithString:escapedUrlString]]; [request setRequestMethod:@"POST"]; [request addRequestHeader:@"Content-Type" value:@"application/xml"];
ASIHTTPRequest *request [ASIHTTPRequest alloc] init];
[request setURL:[NSURL URLWithString:escapedUrlString]];
[request setRequestMethod:@"POST"];
[request addRequestHeader:@"Content-Type" value:@"application/xml"];
[request startSynchronous];
但我每次都得到这样的回应:
检测到不正确的NSStringEncoding值0x0000。假设NSStringEncodingASCII。将在不久的将来停止此兼容性映射行为
我想知道是否必须设置post值。我对ASIHTTPRequest包装器没有太多经验,但我可以看到您正在使用
alloc:init
初始化它,而我看到的大多数示例都有一个方便的初始化器requestWithURL:(NSURL*)url
即
ASIHTTPRequest *request = [AIHTTPRequest requestWithURL:escapedUrlString];
我猜,这个方便的initaliser还将为post请求设置一些必需的变量,包括NSStringEnconding
从ASIHTTPRequest文档
处理文本编码
ASIHTTPRequest将尝试读取
接收数据的文本编码
从内容类型标题。如果是
查找文本编码,它将设置
对适当的
NSStringEncoding。如果找不到
标题中的文本编码,它将
使用
defaultResponseEncoding(此选项为默认值
到NSISOLatin1StringEncoding)
当你打电话[请求]时
响应测试将
尝试从中创建字符串
它接收的数据,使用
以编码作为源
编码
正如Rog所说,使用initWithURL或requestWithURL。无论如何,在我的例子中,问题是我连接到一个速度较慢的服务器,请求超时,出现“检测到错误的NSStringEncoding值0x0000”错误 我用以下方法解决了这个问题:
request.timeOutSeconds = 50;
如果您的服务器速度更慢,您可以在50秒以上进行尝试。快速查看代码后确认,事实上就是这样。查看接口文件(ASIHTTPRequest.h)以了解init/dealloc方法的详细信息。