AFNetworking怎么post x-www-form-urlencoded类型的数据

NSMutableURLRequest*request = [NSMutableURLRequestrequestWithURL:[NSURLURLWithString:url]];

[request setTimeoutInterval:ACTION_TIMEOUT];

[request setHTTPMethod:@"POST"];

[request setValue:@"application/x-www-form-urlencoded"forHTTPHeaderField:@"Content-Type"];

request.HTTPBody=@"key1=value1&key2=value2....";

AFHTTPRequestOperation* operation = [[AFHTTPRequestOperation alloc] initWithRequest:_request];

[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation,idresponseObject) {

NSLog(@"operation hasAcceptableStatusCode: %d", [operation.response statusCode]);

} failure:^(AFHTTPRequestOperation *operation,NSError*error) {

if(error.code !=NSURLErrorTimedOut) {

NSLog(@"error: %@", error);

}

}];

[operation start];



HTTPBody需要从NSString转NSData

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容