无论我尝试什么,我都会得到" App Transport Security阻止了一个明文HTTP(http://)资源加载,因为它不安全。"

时间:2016-03-19 20:05:05

标签: ios http ssl alamofire

我试图向我的个人网站发出alamofire GET请求,但我还没有ssl。我尝试将以下代码行添加到info.plist中,而STILL则没有运气:

1)完全禁用它

<key>NSAppTransportSecurity</key>
<dict>
 <!--Include to allow all connections (DANGER)-->
  <key>NSAllowsArbitraryLoads</key>
      <true/>
</dict>

2)允许我的个人网址

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSExceptionDomains</key>
  <dict>
    <key>yourserver.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>

但我一直得到同样的错误......

2016-03-19 13:02:07.770 appName[51705:9917289] 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.
[Request]: <NSMutableURLRequest: 0x7fcc92032140> { URL: http://www.myurl.com/sup?geoSearchWord=test }
[Response]: nil
[Data]: 0 bytes
[Result]: FAILURE: Error Domain=NSURLErrorDomain Code=-1022 "The resource could not be loaded because the App Transport Security policy requires the use of a secure connection." 

3 个答案:

答案 0 :(得分:3)

Swift 5.2: 您需要在info.plist中添加一个名为“ App Transport Security Settings”的字典,并在其中添加一个名为“ Allow Arbitrary Loads”的键,其值为“ YES” 像这样: info.plist

答案 1 :(得分:1)

第一个解决方案应该有效。请确保将该代码放在第一个Info.plist标记下的<dict>中。还要确保您更改的plist是项目设置Build settings -> Info.plist file中使用的plist。

答案 2 :(得分:0)

您必须在.plist文件中的NSAllowsArbitraryLoads词典下将NSAppTransportSecurity键设置为YES。

NSAllowArbitraryLoads