I am using ASIHTTPRequest to POST data to a remote server on iPhone 4.2.1. When I make the following post request to our server, I get a 400 response (I removed the IP address):
NSString dataString = @"data1=00&data2=00&data3=00";
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:<ipremoved>]]];
[request appendPostData:[dataString dataUsingEncoding:NSUTF8StringEncoding]];
[request setRequestMethod:@"POST"];
[request addRequestHeader:@"User-Agent" value:@"iphone app"];
[request addRequestHeader:@"Content-Type" value:@"application/octet-stream"];
request.delegate = self;
[request startAsynchronous];
When I send the same data using curl, I receive a 200 response:
curl -H "User-Agent: iphone app" -H "Accept:" -H "Content-Type:application/octet-stream" --data-ascii "data1=00&data2=00&data3=00" --location <ipremoved> -v
My colleague is stating that, in the failure case, the ASIHTTPRequest requires two socket reads: one for the header and one for the data. Apparently the server is not presently equipped to parse this correctly, so I am trying to work around it.
If I setup a proxy between iPhone and my Mac and run Paros (to see packets), the problem goes away. Paros combine the header and data so that it is all acquired by the server in a single socket read.
I've tried a few things suggested in other posts including disabling persistent connections, but I am not having any luck. I've also tried doing a ASIHTTPFormRequest, but the server does not like the generated data format.
Any suggestions would be appreciated.
Thanks.