接受'的自签名证书;本地主机';在iOS中

接受'的自签名证书;本地主机';在iOS中,ios,security,ssl,Ios,Security,Ssl,我已经阅读了关于这个主题的所有答案,但对于运行在localhost上的自签名的证书,我仍然存在问题。我的iOS测试非常简单: Alamofire.request("https://localhost:4567/hello").responseJSON { (dataRes) in guard let jsonData = dataRes.data else { return } NSLog("Received JSON: \(jsonData)") } 这将导致输出: 2016-11-

我已经阅读了关于这个主题的所有答案,但对于运行在
localhost
上的自签名的证书,我仍然存在问题。我的iOS测试非常简单:

Alamofire.request("https://localhost:4567/hello").responseJSON { (dataRes) in
  guard let jsonData = dataRes.data else { return }
  NSLog("Received JSON: \(jsonData)")
}
这将导致输出:

2016-11-06 10:59:12.566 Chatty[20454:772766] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802)
2016-11-06 10:59:12.583 Chatty[20454:772681] Received JSON: 0 bytes
使用以下
Info.plist

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <false/>
    <key>NSExceptionDomains</key>
    <dict>
        <key>localhost:4567</key>
        <dict>
            <key>NSAllowsArbitraryLoads</key>
            <true/>
        </dict>
    </dict>
</dict>
其他应用程序(如我的摩卡测试)连接良好,Safari:

理想情况下,我想更新我的iOS模拟器,只接受这个自签名证书(我有
.cer
文件,甚至把它拖到模拟器中并“信任”它,没有明显的效果),不过,如果这是唯一的方法,我也可以排除
localhost
,但这两种方法似乎都不起作用

我错过了什么

编辑:将我的
Info.plist
更新为以下内容也会将
-9802
作为错误代码留给我:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>localhost:4567</key>
        <dict>
            <key>NSAllowsArbitraryLoads</key>
            <true/>
            <key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
            <true/>
        </dict>
    </dict>
</dict>
NSAppTransportSecurity
NSExceptionDomains
本地主机:4567
NSAllowsArbitraryLoads
N第三方异常低安全Http负载

可能尝试使用端口
8080
或端口
443
…我更新了web服务器和iOS应用程序,使其在
8080
上运行,没有任何更改。您可能需要添加
NSThirdPartyExceptionAllowsInsecureHTTPLoads
键并将其设置为true。(即,
NSAppTransportSecurity
NSExceptionDomains
your.domain.com
NSThirdPartyExceptionAllowsInsecureHTTPLoads
)。此外,我认为您拥有的第一个
nsAllowsArbityLoads
False
是全局设置的,所以它覆盖了它后面的
NSExceptionDomains
。@l'l'l不幸的是,这些更改也给我留下了
-9802
-问题更新为我尝试使用的最后一个
Info.plist
2016-11-06 11:01:22.773 Chatty[20750:776671] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813)
<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>localhost:4567</key>
        <dict>
            <key>NSAllowsArbitraryLoads</key>
            <true/>
            <key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
            <true/>
        </dict>
    </dict>
</dict>