我尝试向我的服务器发出 http 请求以获取JSON,但每次尝试时都会收到此错误消息。
2018-03-26 16:53:32.477431+0200 S_Buddy[40041:3435695] [] nw_socket_connect 连接失败(fd 8, 172.227.96.127:443 流,pid:40041,净化 url:https://www.ecb.europa .eu/stats/eurofxref/eurofxref-hist.xml, tls): [64] 主机已关闭 2018-03-26 16:53:32.479737+0200 S_Buddy [40041:3435695] TIC TCP 连接失败 [1:0x60400017f5c0]: 3:64 Err(64) 2018-03-26 16:53:32.480346+0200 S_Buddy[40041:3435695] NSURLSession/NSURLConnection HTTP 加载失败 (kCFStreamErrorDomainSSL, 64) 2018-03-26 16:53:32.480465+0200 S_Buddy[40041:3435695] 任务 <2DA14B-F93-4-4-4 92EB-AF8BE012833F>.<1> HTTP 加载失败(错误代码:-1200 [3:64])2018-03-26 16:53:32.480970+0200 S_Buddy[40041:3435696] 任务 <2DA19979-F9F3-4F4B-92EB -AF8BE012833F>.<1> 以错误结束 - 代码:-1200 错误域=NSURLErrorDomain 代码=-1200 “发生 SSL 错误,无法与服务器建立安全连接。” UserInfo={_kCFStreamErrorCodeKey=64, NSLocalizedRecoverySuggestion=您还是要连接到服务器吗?,https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist.xml?c9911b4d481e6ada019ba2d93f6cf780,NSErrorFailingURLStringKey= https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist.xml?c9911b4d481e6ada019ba2d93f6cf78 _ _ _kCFStreamErrorDomainKey=3}
我的info.plist配置是:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>ecb.europa.eu</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSTemporaryExceptionMinimumTSLVersion</key>
<string>TLSv1.0</string>
<key>NSTemporaryExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
</dict>
</dict>
我的 iOS 目标是 10,我使用 Swift 4