美文网首页
iOSDev AFNetworking使用中遇到的问题

iOSDev AFNetworking使用中遇到的问题

作者: Senjougahara | 来源:发表于2016-11-08 21:03 被阅读42次

AFNetworking

AFNworking是一个强大的第三方网络框架,在这里写写在使用中遇到的问题。


HTTP

开始发送HTTP请求时可能遇到控制台输出以下错误:

App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file

解决方法:

  1. 在info.plist文件中添加一个App Transport Security Settings的属性Dictionary类型
  2. App Transport Security Settings属性下再添加名为Allow Arbitrary LoadsBoolean类型属性取值为YES(如下图所示)
01.png

使用AFNetworking时遇到的错误

有的JSON返回格式为text/html,你会遇到如下错误

Request failed: unacceptable content-type: text/html

AFNetworking框架不支持这个格式,此时你应该在你的代码添加:

 manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];

这样输出的就是正常格式了。

相关文章

网友评论

      本文标题:iOSDev AFNetworking使用中遇到的问题

      本文链接:https://www.haomeiwen.com/subject/neewuttx.html