Reputation: 5823
As stated in title, I send a POST
request using ASIHTTPRequest
and it fails, but the same POST
request works in HTTPClient
, am I doing something wrong?
- (void)postData:(NSData *)postData {
//...
NSMutableData *mutableData = [postData.mutableCopy autorelease];
[request setRequestMethod:@"POST"];
[request setPostBody:mutableData];
[request setPostLength:mutableData.length];
//....
}
Upvotes: 1
Views: 339
Reputation: 266
That's not quite enough in all cases, at least I also had to add the correct Content-Type header to the request:
[request addRequestHeader:@"Content-Type" value:@"application/x-www-form-urlencoded"];
[request appendPostData:[theString dataUsingEncoding:NSUTF8StringEncoding]]
Upvotes: 1
Reputation: 5823
OK I found the problem, for some reason I cannot do
[request setPostBody]
I have to use
[request appendPostData:[theString dataUsingEncoding:NSUTF8StringEncoding]]
instead.
Upvotes: 1