我必须在我的应用程序中发出POST请求,并且我有一个esb.dummy.com.crt证书。我需要证书才能访问服务器。
let request = NSMutableURLRequest(URL: NSURL(string: "https://esb.dummy.com/Common/MyPing?wsdl")!)
request.HTTPMethod = "POST"
request.timeoutInterval = 90
request.setValue("Basic XYZ", forHTTPHeaderField: "Authorization")
request.HTTPBody = getPingBody()
NSURLSession.sharedSession().dataTaskWithRequest(request){...}.resume()
如何将证书添加到应用程序或其他内容以发出请求?
答案 0 :(得分:1)
执行Handling App Transport Security (kCFStreamErrorDomainSSL, -9802)之前提到的内容
但也要添加NSTemporaryExceptionAllowsInsecureHTTPLoads
和NSTemporaryExceptionMinimumTLSVersion
个键。
示例:
<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>