iOS 对https App内部的http请求进行白名单设置

苹果从iOS9开始要求应用使用Https链接来对请求进行加密,来保证数据的安全.如果使用http请求将会报错,当然,如果你想继续使用http请求,有两种方式:

1.使用ASIHttpRequest来请求,ASI是使用CFNetwork来处理请求的,更底层些,避开了苹果的限制

2.在Info.plist文件设置如下

<key>NSAllowsArbitraryLoads</key>

<true/>

目前,应用基本是都https请求了,但有的第三方请求需要http,这个时候就需要白名单了,设置如下:

<dict>

        <key>NSAllowsArbitraryLoads</key>

        <false/>

<key>NSExceptionDomains</key>

<dict>

            <key>youappdomain.com</key>

            <dict>

                <key>NSExceptionAllowsInsecureHTTPLoads</key>

                <true/>

                <key>NSExceptionRequiresForwardSecrecy</key>

                <false/>

                <key>NSIncludesSubdomains</key>

                <true/>

                <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>

                <false/>

</dict>

            <key>aliyuncs.com</key>

            <dict>

                <key>NSExceptionAllowsInsecureHTTPLoads</key>

                <true/>

                <key>NSExceptionRequiresForwardSecrecy</key>

                <false/>

                <key>NSIncludesSubdomains</key>

                <true/>

                <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>

                <false/>

            </dict>

</dict>

</dict>

请求http不成功,也许是因为少了对"Info.plist"的配置。

由于iOS9改用更安全的https,为了能够在iOS9中正常使用http发送网络请求,打开工程中的"Info.plist"中进行如下配置。

猜你喜欢

转载自blog.csdn.net/weixin_42610770/article/details/130547550
今日推荐