AFNetworking请求出现问题

   /* "error == Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/plain" UserInfo={com.alamofire.serialization.response.error.response={ URL: http://192.168.0.192/api/grey/blood_pressure/upload_data } { status code: 200, headers {
    
    Connection = "keep-alive";
    
    "Content-Type" = "text/plain;charset=UTF-8";
    
    Date = "Fri, 25 Nov 2016 01:05:46 GMT";
    
    Server = "nginx/1.11.5";
    
    "Transfer-Encoding" = Identity;
    
     NSErrorFailingURLKey=http://192.168.0.192/api/grey/blood_pressure/upload_data, com.alamofire.serialization.response.error.data=<7b227265 73756c74 5f636f64 65223a22 30222c22 72657375 6c745f6d 7367223a 22737563 63657373 227d>, NSLocalizedDescription=Request failed: unacceptable content-type: text/plain}"

//请不要慌张, 只需要你在AFNetworking的第三方框架内找到AFURLResponseSerialization.m 文件

//修改第228行代码, 添加一项@"text/plain", 同时添加@"text/xml"也是在这个地方:

//    self.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", nil];

    self.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/plain",@"text/json", @"text/javascript", nil];*/



或者

NetworkRequest setStaticHeaderForRequestSerializer:manager.requestSerializer responseSerializer:manager.responseSerializer];

+ (void) setStaticHeaderForRequestSerializer: (AFHTTPRequestSerializer *) request responseSerializer: (AFHTTPResponseSerializer *) response
{
    response.acceptableContentTypes = [NSSet setWithObjects:@"text/javascript", @"application/json", @"text/json", @"text/html", @"text/plain", @"charset=utf-8", nil];
    [request setValue:@"gzip" forHTTPHeaderField:@"Accept-Encoding"];//固定字符串:gzip
    [request setValue:@"close" forHTTPHeaderField:@"Connection"];//固定字符串:close
}
    /*  添加token到请求头的代码如下:
 
 NSDictionary *dict =  @{@"name" : @"小明",
 
 @"age" :@"20"
 
 };
 
 //实例化AFHTTPSessionManager
 
 AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
 
 //调出请求头
 
 manager.requestSerializer = [AFJSONRequestSerializer serializer];
 
 //将token封装入请求头
 
 [manager.requestSerializer setValue:TOKEN forHTTPHeaderField:@"token-id"];
 
 //post上传文件
 
 [manager POST:@"http://192.168.0.90/****" parameters:dict progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
 
 NSLog(@"上传成功 === %@",responseObject);
 
 } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
 
 NSLog(@"上传错误 == error == %@",error);
 
 }];

*/

你可能感兴趣的:(AFNetworking请求出现问题)