如何在iOS 9中加载HTTPS URL?

时间:2016-02-25 08:38:35

标签: ios objective-c

我需要在info.plist中设置什么设置才能启用HTTPS模式?我已经把它放在我的plist中了:

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

但它无法正常工作,我仍然收到此错误

  

错误讯息: -

     

2016-02-25 12:46:31.860 Indus Audio [707:13224] NSURLSession / NSURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9813)

     

2016-02-25 14:20:31.119 Indus Audio [817:23670]响应:(null)错误域= NSURLErrorDomain代码= -1202&#34;此服务器的证书无效。您可能连接到假装是“www.indusaudio.com”的服务器,这可能会使您的机密信息面临风险。&#34;

     

UserInfo = {NSURLErrorFailingURLPeerTrustErrorKey =,NSLocalizedRecoverySuggestion =你想要连接到服务器吗?,_ kCFStreamErrorDomainKey = 3,_kCFStreamErrorCodeKey = -9813,   NSErrorPeerCertificateChainKey = {type = immutable,count = 1,values =(       0:   },NSUnderlyingError = 0x7f9e58e05cf0 {错误域= kCFErrorDomainCFNetwork代码= -1202&#34;(null)&#34; UserInfo = {_ kCFStreamPropertySSLClientCertificateState = 0,kCFStreamPropertySSLPeerTrust =,_ kCFNetworkCFStreamSSLErrorOriginalValue = -9813,_kCFStreamErrorDomainKey = 3,_kCFStreamErrorCodeKey = -9813,kCFStreamPropertySSLPeerCertificates = {type = immutable,count = 1,values =(       0:   )}}},

网址:https://www.xxxxx.com/xxx/xxx/files/downloadFile/en/linto

2 个答案:

答案 0 :(得分:1)

<强>更新 更好地更新您的服务器以支持SSL和TLSv1.2

仅用于临时。这种方法并非完全可取:

   <key>NSAppTransportSecurity</key>
<dict>
    <!--Connect to anything. Not advisable. For desperate measures I guess-->
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

原始答案:

iOS 9支持TLSv1.2,请参阅this document。因此,通过将其更改为TLSv1.1,它会绕过安全性(这不是完全可取的)。另外,请指定url,如下所示:

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

答案 1 :(得分:-1)

在info.plist文件中添加应用传输安全设置,并将允许任意载入项设置为YES。