ios https与http混合使用

来源:互联网 发布:linux c执行shell命令 编辑:程序博客网 时间:2024/05/23 11:45

因项目中使用的https请求,但是调用三方接口(如银行卡四元素校验)时,接口不支持https。

这时候在项目中既需要https请求也要对http的请求放行

如果直接做如下操作则失去了本身https的用意

修改info.plist

<key>NSAppTransportSecurity</key>    <dict>      <key>NSAllowsArbitraryLoads</key>    <true/>    </dict>

所以我们只需要对不支持https的域名做特殊设置即可代码如下修改info.plist

    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSExceptionDomains</key>
        <dict>
            <key>apis.haoservice.com</key>
            <dict>
                <key>NSExceptionAllowsInsecureHTTPLoads</key>
                <true/>
                <key>NSExceptionRequiresForwardSecrecy</key>
                <false/>
                <key>NSIncludesSubdomains</key>
                <true/>
            </dict>
        </dict>
    </dict>