Swift:如何使用服务器SSL证书进行Https请求

Sha*_*anu 1 ssl https ios swift

嗨,我想在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)")


            }
    }
Run Code Online (Sandbox Code Playgroud)

我已经使用上面的代码来发出请求和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>
Run Code Online (Sandbox Code Playgroud)

在plist中我已经给出了这样的但是我仍然得到错误

NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813)
Run Code Online (Sandbox Code Playgroud)

Fen*_*nec 5

重要提示:请勿在生产中使用此产品.基本上,使用Alamofire,您可以绕过应用程序开发和测试目的的身份验证.确保在应用程序位于App Store或生产中之前将其删除: -

func bypassURLAuthentication() {
        let manager = Alamofire.Manager.sharedInstance
        manager.delegate.sessionDidReceiveChallenge = { session, challenge in
            var disposition: NSURLSessionAuthChallengeDisposition = .PerformDefaultHandling
            var credential: NSURLCredential?
            if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust {
                disposition = NSURLSessionAuthChallengeDisposition.UseCredential
                credential = NSURLCredential(forTrust: challenge.protectionSpace.serverTrust!)
            } else {
                if challenge.previousFailureCount > 0 {
                    disposition = .CancelAuthenticationChallenge
                } else {
                    credential = manager.session.configuration.URLCredentialStorage?.defaultCredentialForProtectionSpace(challenge.protectionSpace)
                    if credential != nil {
                        disposition = .UseCredential
                    }
                }
            }
            return (disposition, credential)
        }
    }
Run Code Online (Sandbox Code Playgroud)

谢谢!如果这有帮助,请告诉我.:)