原文链接:http://blog.csdn.net/mumubumaopao/article/details/50267353
在使用AFNetworking的时候,经常会遇到这个问题,网上的很多方法是去self.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", nil]添加字段text/html,但是我添加之后还是不能成功的请求下来数据,后来耐着性子看了下错误原因,原来是要添加text/plain字段,于是就在代码里添加了下面这行代码
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"];
可以成功的请求下来数据了.
附上自己写得demo:
//自己写使用AFNetworking进行post请求的demo
AFHTTPRequestOperationManager * manager = [AFHTTPRequestOperationManager manager ];
//声明请求的结果是json类型
manager.responseSerializer = [AFJSONResponseSerializer serializer];
//添加可以请求的字段
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"];
//http://ipad-bjwb.bjd.com.cn/DigitalPublication/publish/Handler/APINewsList.ashx?date=20131129&startRecord=1&len=5&udid=1234567890&terminalType=Iphone&cid=213
NSDictionary * parameters = @{@"date":@"20131129",@"startRecord":@"1",@"len":@"5",@"udid":@"1234567890",@"terminalType":@"Iphone",@"cid":@"213"};
NSString * url =@"http://ipad-bjwb.bjd.com.cn/DigitalPublication/publish/Handler/APINewsList.ashx?date=20131129&startRecord=1&len=5&udid=1234567890&terminalType=Iphone&cid=213";
[manager POST:url parameters:parameters success:^(AFHTTPRequestOperation * _Nonnull operation, id _Nonnull responseObject) {
NSLog(@"json = %@",responseObject);
} failure:^(AFHTTPRequestOperation * _Nonnull operation, NSError * _Nonnull error) {
NSLog(@"%@",error);
}];
加入审核被拒交流群,一起交流审核上架经验吧~~ 群号:689757099