根据以下错误消息,我需要在info.plist中设置什么来启用HTTP模式?

传输安全性已阻止明文HTTP(HTTP://)资源因为它是不安全的。可以通过以下方式配置临时异常应用程序的Info.plist文件。

假设我的域名是example.com。


当前回答

注意:plist中的异常域应该是小写。

示例:您已在“设置”->“共享”下将计算机命名为“MyAwesomeMacbook”;您的服务器(出于测试目的)正在MyAwesomeMacbook.local:3000上运行,您的应用程序需要向http://MyAwesomeMacbook.local:3000/files...,您的plist需要指定“myawesomemacbook.local”作为异常域。

--

您的info.plist将包含。。。

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSExceptionDomains</key>
  <dict>
    <key>myawesomemacbook.local</key>
    <dict>
      <!--Include to allow subdomains-->
      <key>NSIncludesSubdomains</key>
      <true/>
      <!--Include to allow HTTP requests-->
      <key>NSExceptionAllowsInsecureHTTPLoads</key>
      <true/>
    </dict>
  </dict>
</dict>

其他回答

以下是直观的设置:

请参阅论坛帖子应用程序传输安全?。

例如,您可以添加特定域,如:

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSExceptionDomains</key>
  <dict>
    <key>example.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>

懒惰选项是:

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

###注:

info.plist是一个XML文件,因此您可以将这些代码或多或少地放在文件中的任何位置。

如果您使用的是Xcode 8.0+和Swift 2.2+,甚至是Objective C:

如果要允许到任何站点的HTTP连接,可以使用以下键:

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

如果您知道要连接到哪些域,请添加:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>example.com</key>
        <dict>
            <key>NSExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <key>NSIncludesSubdomains</key>
            <true/>
        </dict>
    </dict>
</dict>

**终于!!!已解决的应用程序传输安全**

  1. Follow the follow the screen shot. Do it in Targets info Section.

这是在iOS 9 GM种子上进行测试和工作的-这是允许特定域使用HTTP而不是HTTPS的配置:

<key>NSAppTransportSecurity</key>
<dict>
      <key>NSAllowsArbitraryLoads</key> 
      <false/>
       <key>NSExceptionDomains</key>
       <dict>
            <key>example.com</key> <!--Include your domain at this line -->
            <dict>
                <key>NSIncludesSubdomains</key>
                <true/>
                <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
                <true/>
                <key>NSTemporaryExceptionMinimumTLSVersion</key>
                <string>TLSv1.1</string>
            </dict>
       </dict>
</dict>

NSAllowsArbitraryLoads必须为false,因为它不允许所有不安全的连接,但例外列表允许连接到一些没有HTTPS的域。

这里是直观的: