iOS"Request failed: unacceptable content-type: text/html"
获取服务器响应出错
} }, NSErrorFailingURLKey=http://172.16.1.31:7001/itom/getwork, com.alamofire.serialization.response.error.data=<5b7b2273 74617475 73223a22 73756363 65737322 2c226d73 67223a22 e799bbe9 9986e688 90e58a9f 227d5d>, NSLocalizedDescription=Request failed: unacceptable content-type: text/html}
I also encountered the same problem. This means that your server is sending "text/html" "text/html" acceptableContentTypes AFURLResponseSerializati @"text/html"
I hope this helps you. Best regards and less bugs as possible in the code.
op.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html”];
对应到自己的项目里面,我用的是AFNetworking这套网络请求包,需要改的是:
AFURLResponseSerializati
223行:
self.acceptableContentTypes
加上蓝色部分,其实就是添加一种服务器返回的数据格式。
本文详细介绍了如何解决iOS网络请求中遇到的错误,该错误提示服务器响应的内容类型为text/html,而不是已支持的类型。通过在AFNetworking的AFURLResponseSerialization类中添加text/html到acceptableContentTypes集合中,可以解决此问题。理想情况下,应从服务器端更改数据类型,但若不可行,则可采取此临时解决方案。
1万+

被折叠的 条评论
为什么被折叠?



