hzxu
hzxu

Reputation: 5823

ASIHTTPRequest Post request fails while works via HTTPClient

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

Answers (2)

Karvapallo
Karvapallo

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

hzxu
hzxu

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

Related Questions