我试图向我的个人网站发出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."
答案 0 :(得分:3)
Swift 5.2: 您需要在info.plist中添加一个名为“ App Transport Security Settings”的字典,并在其中添加一个名为“ Allow Arbitrary Loads”的键,其值为“ YES” 像这样:
答案 1 :(得分:1)
第一个解决方案应该有效。请确保将该代码放在第一个Info.plist
标记下的<dict>
中。还要确保您更改的plist是项目设置Build settings -> Info.plist file
中使用的plist。
答案 2 :(得分:0)
您必须在.plist文件中的NSAllowsArbitraryLoads
词典下将NSAppTransportSecurity
键设置为YES。