简体   繁体   中英

Add certificate to https request on iOS

I have to make a POST request in my app and I have a esb.dummy.com.crt certificate. I need the certificate access the server.

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

How can I add the certificate to the app or something to make the request?

Do what mentioned before Handling App Transport Security (kCFStreamErrorDomainSSL, -9802)

But add NSTemporaryExceptionAllowsInsecureHTTPLoads and NSTemporaryExceptionMinimumTLSVersion keys also.

Example:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM