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

WBOY
Release: 2016-06-24 11:31:22
Original
2054 people have browsed it

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

 

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!