AFJSONRequestOperation不支持”text/html”问题

问题描述:输入法用AFJSONRequestOperation获取服务器更新消息。发现AFNetworking示例可以使用,换了服务器访问地址就不行了。

问题分析:打印出错误消息,如下:

Error Domain=AFNetworkingErrorDomain Code=-1016 "Expected content type {(
"text/json",
"application/json",
"text/javascript"
)}, got text/html"

看来是AFJSONRequestOperation只支持3种META,而服务器返回的是"text/html"。

问题解决:增加如下代码,让AFJSONRequestOperation支持"text/html"。

[AFJSONRequestOperationaddAcceptableContentTypes:[NSSetsetWithObjects:@"text/html", nil]];