通过HTTPClient工作时,ASIHTTPRequest发布请求失败 [英] ASIHTTPRequest Post request fails while works via HTTPClient

查看:89
本文介绍了通过HTTPClient工作时,ASIHTTPRequest发布请求失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如标题中所述,我使用ASIHTTPRequest发送POST请求,但失败,但是相同的POST请求在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];
    //....
}

推荐答案

在所有情况下都还不够,至少我还必须在请求中添加正确的Content-Type标头:

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

这篇关于通过HTTPClient工作时,ASIHTTPRequest发布请求失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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