发布于 3年前

Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/html" 的问题原因及解决方案

Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/html"

此问题的原因就是使用的第三方框架AFNetworking 接口返回值类型不确定,由于服务器人员习惯于使用html文件所以将json文件也这么写了,导致没法解析

在模型类或者网络工具类中添加这句代码就能完美解决上述问题,建议不要直接修改AFNetworking,肯能会出现一些莫名的问题

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

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

在AFNetworking的AFURLResponseSerialization.m文件中能找到,我们只是添加了"text/html",这样就可以解析后缀名为html的json数据了

©2020 edoou.com   京ICP备16001874号-3