【发布时间】:2016-07-06 00:58:01
【问题描述】:
您好,我想在 Swift 中发出 Https 请求。目前我通过 ip 地址访问本地服务器。本地服务器通过访问要向当前正在这样做的服务器发出请求的证书来获得一个 SSL 证书。
Alamofire.request(.GET, https://ipaddress//, parameters: [param], headers: headers)
.responseJSON { response in
print(response.request) // original URL request
print(response.response) // URL response
print(response.data) // server data
print(response.result) // result of response serialization
if let JSON = response.result.value {
print("JSON: \(JSON)")
}
}
我已经使用上面的代码发出请求并在 plist 中
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>192.168.2.223:1021(my local ip)</key>
<dict>
Include to allow subdomains-->
<key>NSIncludesSubdomains</key>
<true/>
<!--Include to allow insecure HTTP requests-->
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<!--Include to specify minimum TLS version-->
<key>NSTemporaryExceptionMinimumTLSVersion</key>
<string>TLSv1.1</string>
</dict>
</dict>
</dict>
在 plist 中我已经给出了这样的结果,但我仍然收到类似的错误
NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813)
【问题讨论】:
-
您不能在 ATS plist 值中使用 IP 地址。
-
你找到解决方案了吗?