在iOS上将证书添加到https请求

时间:2016-08-10 13:22:59

标签: ios swift ssl https

我必须在我的应用程序中发出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()

如何将证书添加到应用程序或其他内容以发出请求?

1 个答案:

答案 0 :(得分:1)

执行Handling App Transport Security (kCFStreamErrorDomainSSL, -9802)之前提到的内容

但也要添加NSTemporaryExceptionAllowsInsecureHTTPLoadsNSTemporaryExceptionMinimumTLSVersion个键。

示例:

<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>