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

时间:2016-03-19 06:04:58

标签: ios swift ssl https

您好我想在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)

1 个答案:

答案 0 :(得分:5)

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

 Update @Tbl
  set value1=value1+value1 
 update @Tbl set value2=value1

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

相关问题