在ASIHTTPRequest中POST中的空体 [英] Empty body in POST in ASIHTTPRequest

查看:225
本文介绍了在ASIHTTPRequest中POST中的空体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我发送一个空数据正文的POST请求:

Basically, I am sending a POST request with an empty data body:

  ASIHTTPRequest *request [ASIHTTPRequest alloc] init];
  [request setURL:[NSURL URLWithString:escapedUrlString]];
  [request setRequestMethod:@"POST"];
  [request addRequestHeader:@"Content-Type" value:@"application/xml"];
  [request startSynchronous];

但我每次都收到此回复:

But i am getting this response each time:

检测到错误的NSStringEncoding值0x0000。假设NSStringEncodingASCII。将在不久的将来停止这种兼容性映射行为。

Incorrect NSStringEncoding value 0x0000 detected. Assuming NSStringEncodingASCII. Will stop this compatiblity mapping behavior in the near future.

我想知道是否必须设置帖子值。

I am wondering if it's mandatory to set post values.

推荐答案

我对ASIHTTPRequest包装器没有太多经验,但我可以看到你用 alloc:init 初始化它,而大多数我见过的示例有一个方便的初始化 requestWithURL:(NSURL *)url ie

I don't have much experience with the ASIHTTPRequest wrapper but I can see you are initialising it with alloc:init whilst most examples I've seen have a convenience initialiser requestWithURL:(NSURL*)url i.e.

ASIHTTPRequest *request = [AIHTTPRequest requestWithURL:escapedUrlString];

我猜这个便利initaliser也会为你的帖子设置一些必要的变量请求工作,包括 NSStringEnconding

At a guess I'd say this convenience initaliser will also set some of the required variables for your post request to work, including NSStringEnconding.

来自http://allseeing-i.com/ASIHTTPRequest/How-to-use#handling_text_encodings


处理文本编码

Handling text encodings

ASIHTTPRequest将尝试读取
从接收数据
的文本编码Content-Type标头。如果
找到文本编码,它会将
responseEncoding设置为适当的
NSStringEncoding。如果它在标题中没有找到
a文本编码,那么
将使用
defaultResponseEncoding的值(这默认为
到NSISOLatin1StringEncoding)。

ASIHTTPRequest will attempt to read the text encoding of the received data from the Content-Type header. If it finds a text encoding, it will set responseEncoding to the appropriate NSStringEncoding. If it does not find a text encoding in the header, it will use the value of defaultResponseEncoding (this defaults to NSISOLatin1StringEncoding).

当你调用[request
responseString]时,ASIHTTPRequest将
尝试从它收到的
数据创建一个字符串,使用
responseEncoding作为源
encoding。

When you call [request responseString], ASIHTTPRequest will attempt to create a string from the data it received, using responseEncoding as the source encoding.

这篇关于在ASIHTTPRequest中POST中的空体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆