Error Domain=com.alamofire.error.serialization.response Code=-1016 “Request failed: unacceptable con…

  • Post author:
  • Post category:其他


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数据了

转载于:https://www.cnblogs.com/Jusive/p/5077322.html