使用afnetworking请求一个网站出现了以下错误
error domain=com.alamofire.error.serialization.response code=-1016 request failed: unacceptable content-type: text/html userinfo={com.alamofire.serialization.response.error.response= { url: http://xxx.xxx.xxx } { status code: 200, headers { content-encoding = gzip; content-type = text/html; date = sat, 10 oct 2015 13:44:28 gmt; server = nginx/1.4.1; vary = accept-encoding; x-cache = miss from rj-zsbgp-cdn-75; x-powered-by = php/5.4.16;} }, nserrorfailingurlkey=http://xxx.xxx.xxx, com.alamofire.serialization.response.error.data=, nslocalizeddescription=request failed: unacceptable content-type: text/html}
解决方法:
修改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
如果你不是在wb145230博客园看到本文,请点击查看原文.