Swift - 网络请求报App Transport Security has blocked a cleartext错

来源:互联网 发布:vb加减乘除代码 编辑:程序博客网 时间:2024/06/13 09:34


http://www.hangge.com/blog/cache/detail_822.html


使用Xcode7编写iOS9应用时,如果获取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.

原因:
从iOS9起,新特性要求App访问网络请求,要采用 HTTPS 协议。 

如果仍想要使用HTTP协议,解决办法如下:
1,在Info.plist中添加 NSAppTransportSecurity 类型 Dictionary ;
2,在 NSAppTransportSecurity 下添加 NSAllowsArbitraryLoads 类型Boolean ,值设为 YES;
原文:Swift - 网络请求报App Transport Security has blocked a cleartext错


当然,也可以直接使用Source Code形式打开Info.plist,添加如下配置:
1
2
3
4
5
<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

原文出自:www.hangge.com  转载请保留原文链接:http://www.hangge.com/blog/cache/detail_822.html

0 0
原创粉丝点击