我在我的代码中使用了 ASIHTTPRequest API。GET 请求成功,但 POST 请求不起作用。唯一的区别是,在 POST 请求的情况下,我附加了用 NSUTF8Encoding 编码的 post 数据。POST API 适用于 Android 应用程序。以下是我的代码:
NSString *strToken = [NSString stringWithFormat:@"access_token=\"%@\"", securityToken];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:url]];
[request addRequestHeader:@"ContentType" value:@"application/json"];
[request addRequestHeader:@"Authorization" value:strToken];
if( type == GET )
[request setRequestMethod:@"GET"];
else if( type == POST )
{
[request setRequestMethod:@"POST"];
[request appendPostData:[data dataUsingEncoding:NSUTF8StringEncoding]];
}
else if( type == PUT )
{
[request setRequestMethod:@"PUT"];
[request appendPostData:[data dataUsingEncoding:NSUTF8StringEncoding]];
}
[request setDelegate:owner];
[request startAsynchronous];