应用传输安全已阻止明文 HTTP 资源 [英] App Transport Security has blocked a cleartext HTTP resource
问题描述
我正在 swift 中使用 Socket.IO 库,但我不断收到此错误:
I am using Socket.IO library in swift and I keep getting this error:
应用传输安全已阻止明文 HTTP (http://) 资源加载,因为它不安全.可以通过配置临时异常您应用的 Info.plist 文件.
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.
当我尝试发送 http 请求时.我根据苹果官方文档将密钥添加到 plist 中,但没有帮助.
when I am trying to send an http request. I added the keys to plist according to the official apple documentation, but it did not help.
推荐答案
你需要像这样更正:
为了方便起见,这是 info.plist 中正确的 xml
To make it easier, this is the correct xml in the info.plist
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>localhost</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSTemporaryExceptionMinimumTLSVersion</key>
<string>TLSv1.1</string>
</dict>
</dict>
</dict>
将 localhost
更改为您的实际服务器
change the localhost
to your actual server
检查表格中的 NSAppTransportSecurity 选项
如果您想与任何域进行所有通信,您可以这样做:
If you want to all communications with any domain, you can do this:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
但是,您应该在开发阶段使用最新的.
However, you should use the latest just in the developing phase.
这篇关于应用传输安全已阻止明文 HTTP 资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!