App Transport Security已阻止明文HTTP资源 [英] App Transport Security has blocked a cleartext HTTP resource

查看:92
本文介绍了App Transport Security已阻止明文HTTP资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在swift中使用Socket.IO库并且我一直收到此错误:

I am using Socket.IO library in swift and I keep getting this error:


App Transport Security已阻止明文HTTP(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.

。我根据官方苹果文档添加了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.

这篇关于App Transport Security已阻止明文HTTP资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆