AFNetworking请求错误

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/AlenCzf/article/details/51509882

最近上传json格式的base64 image 出现了以下几个错误,mark下


NSLocalizedDescription=Request failed: unacceptable content-type: text/html 解决方法

使用AFNetworking请求出现了以下错误

 

 
  

Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: internal server error (500)" UserInfo={NSUnderlyingError=0x7f8608dea390 {Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/html" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x7f860b1b7060> { URL: http://120.76.142.118:8080/nursery/api/login/updateheadportrait } { status code: 500, headers {

    Connection = close;

    "Content-Encoding" = gzip;

    "Content-Language" = en;

    "Content-Type" = "text/html;charset=utf-8";

    Date = "Thu, 26 May 2016 11:20:51 GMT";

    Server = "Apache-Coyote/1.1";

    "Transfer-Encoding" = Identity;

    Vary = "Accept-Encoding";

} }

 

解决方法:

修改AFNetworking中AFURLResponseSerialization.m文件

在223行,将

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

改成

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

增加了一个 @"text/html"


不过因为AFNetWorking 一直在更新,所以最好从外部接口调入,方法如下:

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];

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

//这时又报了以下错误:

Error Domain=NSCocoaErrorDomain Code=3840 "JSON text did not start with array or object and option to allow fragments not set."

这时加上代码:

manager.responseSerializer = [AFHTTPResponseSerializer serializer]


但是又报上了新的错误

Code=-1011 "Request failed: internal server error (500)

暂时还未找到方法,网上挺多说是后台的问题,明天问问看,未完待续。


猜你喜欢

转载自blog.csdn.net/AlenCzf/article/details/51509882