首页 文章

App Transport Security已阻止明文HTTP资源

提问于
浏览
11

enter image description here

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

App Transport Security已阻止明文HTTP(http://)资源加载,因为它不安全 . 可以通过应用程序的Info.plist文件配置临时例外 .

当我尝试发送http请求时 . 我根据官方的苹果文档添加了plist键,但它没有帮助 .

6 回答

  • 26

    你需要像这样纠正它:

    enter image description here

    为了更容易,这是info.plist中的正确xml

    <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 更改为您的实际服务器

    Check the table for NSAppTransportSecurity options

    如果您希望与任何域进行所有通信,则可以执行以下操作:

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

    但是,您应该在开发阶段使用最新版本 .

  • 4

    我发现更方便的另一种解决方法是使用 NSAllowsArbitraryLoads 密钥默认禁用App Transport Security . 因此,您未包含在 NSExceptionDomains 字典中的任何域(或者如果您根本不包括 NSExceptionDomains )将不受App Transport Security的约束 .

    enter image description here

  • 6

    我在屏幕截图中看到错误的密钥和拼写错误 . 这是一个工作示例:

    screen

  • 4

    Xcode项目 - >转到info.plist并单击按钮,然后添加(应用程序传输安全设置)展开,允许任意负载设置为是 . 谢谢

  • 1

    我'm working in xCode 8.2. It'有点不同,但编辑PLIST文件需要在 App Transport Security Settings Line中添加这两个项目......:

    Allow Arbitrary LoadsAllow Arbitrary Loads in Web Content ...并给他们两个键 YES .

    它对我有用,希望这对你有用,对不起我的英语 .

    enter image description here

    enter image description here

  • 0

    @William Kinaan有最好的答案,但最好确保在异常域"localhost"下面添加 NSAllowsArbitraryLoads ,而不是在更高的NSTransportSecurity级别打开,直到所有域 .

相关问题