根据以下错误消息,我需要在info.plist中设置什么来启用HTTP模式?
传输安全性已阻止明文HTTP(HTTP://)资源因为它是不安全的。可以通过以下方式配置临时异常应用程序的Info.plist文件。
假设我的域名是example.com。
根据以下错误消息,我需要在info.plist中设置什么来启用HTTP模式?
传输安全性已阻止明文HTTP(HTTP://)资源因为它是不安全的。可以通过以下方式配置临时异常应用程序的Info.plist文件。
假设我的域名是example.com。
当前回答
有两种解决方案:
解决方案1:
在Info.plist文件中添加密钥为“NSAppTransportSecurity”的字典在字典中添加另一个关键字为“允许任意加载”的元素
Plist结构应如下图所示。
解决方案2:
在Info.plist文件中添加密钥为“NSAppTransportSecurity”的字典在字典中添加另一个键为“NSExceptionDomains”的元素添加具有NSDictionary类型的键“MyDomainName.com”的元素添加具有布尔类型的键“NSIncludesSubdomains”且值设置为YES的元素添加具有Boolean类型的键“NSTemporaryExceptionAllowsInsecureHTTPLoads”且值设置为YES的元素
Plist结构应如下图所示。
首选解决方案2,因为它只允许选定的域,而解决方案1允许所有不安全的HTTP连接。
其他回答
2015-09-25(2015-09-18 Xcode更新后):
我用了一种非懒惰的方法,但没有奏效。以下是我的尝试。
第一
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>www.xxx.yyy.zzz</key>
<dict>
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSTemporaryExceptionMinimumTLSVersion</key>
<string>TLSv1.1</string>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
</dict>
</dict>
其次,
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>www.xxx.yyy.zzz</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSExceptionMinimumTLSVersion</key>
<string>TLSv1.1</string>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
</dict>
</dict>
最后,我使用了懒惰的方法:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
这可能有点不安全,但我找不到其他解决方案。
在Swift 5中,我们有两种方法来解决这个问题。我们需要在info.plist中添加NSAppTransportSecurity
我给出了info.plist源代码和图片以供参考
第一个是在info.plist中添加NSAppTransportSecurity->NSAllowsArbitraryLoads。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<false/>
</dict>
</dict>
</plist>
另一种方法是在info.plist中添加NSAppTransportSecurity->NSExceptionDomains,并添加URL的域,并启用加载子域(NSIncludesSubdomains)和允许不安全HTTP加载(NSExceptionAllowsInsecureHTTPLoads)的权限
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>www.7timer.info</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
</dict>
</dict>
</plist>
在swift 4和xocde 10中,将NSAllowsArbitraryLoads更改为允许任意加载。所以它将是这样的:
<key>App Transport Security Settings</key>
<dict>
<key>Allow Arbitrary Loads</key><true/>
</dict>
有两种解决方案:
解决方案1:
在Info.plist文件中添加密钥为“NSAppTransportSecurity”的字典在字典中添加另一个关键字为“允许任意加载”的元素
Plist结构应如下图所示。
解决方案2:
在Info.plist文件中添加密钥为“NSAppTransportSecurity”的字典在字典中添加另一个键为“NSExceptionDomains”的元素添加具有NSDictionary类型的键“MyDomainName.com”的元素添加具有布尔类型的键“NSIncludesSubdomains”且值设置为YES的元素添加具有Boolean类型的键“NSTemporaryExceptionAllowsInsecureHTTPLoads”且值设置为YES的元素
Plist结构应如下图所示。
首选解决方案2,因为它只允许选定的域,而解决方案1允许所有不安全的HTTP连接。
**终于!!!已解决的应用程序传输安全**
1. Follow the follow the screen shot. Do it in Targets info Section.