Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Empty body in POST in ASIHTTPRequest

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:

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.

like image 479
Frank Avatar asked Dec 04 '10 22:12

Frank


2 Answers

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];

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.

From the ASIHTTPRequest documentation at http://allseeing-i.com/ASIHTTPRequest/How-to-use#handling_text_encodings

Handling text encodings

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).

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

like image 177
Rog Avatar answered Nov 08 '22 21:11

Rog


As Rog says, use initWithURL or requestWithURL. Anyway, in my case the problem was that I was connecting to a slow server and the request timed out giving the "Incorrect NSStringEncoding value 0x0000 detected" error.

I solved it with:

request.timeOutSeconds = 50;

You can try with more than 50 second if your server is even slower.

like image 44
Ruben Marin Avatar answered Nov 08 '22 22:11

Ruben Marin