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>

© 版权声明
THE END
如果内容对您有所帮助,就支持一下吧!
点赞0 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容