AFNetworking2.0请求数据时出现错误Requestfailed:unacceptablecontent-type:text/html解决方法

时间:2021-08-04 19:21:30

使用AFNetworking 2.0 请求数据时出现错误 Request failed: unacceptable content-type: text/html 解决方法

添加一行

manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];

即可

整个代码为:

    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];

NSDictionary *parameters = @{@"foo":@"bar"};
[manager POST:@"http://example.com/resources.json" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject)
{
NSLog(@"JSON: %@",responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error)
{
NSLog(@"Error:%@",error);
}];