新版ios禁止HTTP访问的解决方法

RT,直接访问会提示:

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.

解决方法有2种:

参考自:http://stackoverflow.com/questions/31254725/transport-security-has-blocked-a-cleartext-http

See the developer forums: https://forums.developer.apple.com/thread/3544

Also this page: http://ste.vn/2015/06/10/configuring-app-transport-security-ios-9-osx-10-11/

推荐解法,添加域名的白名单:

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSExceptionDomains</key>
  <dict>
    <key>yourserver.com</key>
    <dict>
      <!--Include to allow subdomains-->
      <key>NSIncludesSubdomains</key>
      <true/>
      <!--Include to allow HTTP requests-->
      <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
      <true/>
      <!--Include to specify minimum TLS version-->
      <key>NSTemporaryExceptionMinimumTLSVersion</key>
      <string>TLSv1.1</string>
    </dict>
  </dict>
</dict>

不推荐解法,允许全部HTTP请求:

<key>NSAppTransportSecurity</key>
<dict>
  <!--Include to allow all connections (DANGER)-->
  <key>NSAllowsArbitraryLoads</key>
      <true/>
</dict>

Note:

info.plist is an xml file so you can place this code more or less anywhere inside the file

Leave a Reply

Your email address will not be published.