根据以下错误消息,我需要在info.plist中设置什么来启用HTTP模式?
传输安全性已阻止明文HTTP(HTTP://)资源因为它是不安全的。可以通过以下方式配置临时异常应用程序的Info.plist文件。
假设我的域名是example.com。
根据以下错误消息,我需要在info.plist中设置什么来启用HTTP模式?
传输安全性已阻止明文HTTP(HTTP://)资源因为它是不安全的。可以通过以下方式配置临时异常应用程序的Info.plist文件。
假设我的域名是example.com。
当前回答
iOS 9.0或更高版本提供传输安全。尝试在应用程序中调用WS时可能会出现以下警告:
应用程序传输安全性已阻止明文HTTP(HTTP://)资源加载,因为它不安全。可以通过应用程序的Info.plist文件配置临时异常。
将以下内容添加到Info.plist将禁用ATS:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key><true/>
</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的域。
这里是直观的:
请参阅论坛帖子应用程序传输安全?。
例如,您可以添加特定域,如:
<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文件,因此您可以将这些代码或多或少地放在文件中的任何位置。
在swift 4和xocde 10中,将NSAllowsArbitraryLoads更改为允许任意加载。所以它将是这样的:
<key>App Transport Security Settings</key>
<dict>
<key>Allow Arbitrary Loads</key><true/>
</dict>
开发示例
这里是一个plist的截图,它保持ATS的完整性(=安全),但允许通过HTTP而不是HTTPS连接到本地主机。它在Xcode 7.1.1中工作。