Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift、SSL自签名证书IOS8+;_Swift_Ssl_Nsurlconnection - Fatal编程技术网

Swift、SSL自签名证书IOS8+;

Swift、SSL自签名证书IOS8+;,swift,ssl,nsurlconnection,Swift,Ssl,Nsurlconnection,我想在webservice调用中实现SSL。 但有如下错误: NSURLConnection/CFURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9813) 下面是我的代码 添加的代理如下所示 公共类NetworkUtil:NSObject,NSURLConnectionLegate{ } 如何在上述代码中配置SSL 谢谢,据我所知,唯一的方法是实现方法: 如果您针对的是较旧的版本,则需要method,这是自iOS8以来就不推荐使用的方法。据我所知

我想在webservice调用中实现SSL。 但有如下错误:

NSURLConnection/CFURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9813)

下面是我的代码 添加的代理如下所示 公共类NetworkUtil:NSObject,NSURLConnectionLegate{ }

如何在上述代码中配置SSL


谢谢,

据我所知,唯一的方法是实现方法:


如果您针对的是较旧的版本,则需要method,这是自iOS8以来就不推荐使用的方法。

据我所知,唯一的方法是实现method:


如果您针对的是较旧的版本,则需要method,它自iOS8以来就已被弃用。

hris.to对我不起作用……我针对的是IOS 8.4。请提供您是如何尝试的?我一直在使用它,到目前为止没有遇到任何问题。hris.to,你有机会检查一下吗。仅供参考,我正在使用sendSynchronousRequest请求。未进行连接委派,您无法使用证书。请看本教程如何通过委托方法实现连接。hris.to对我不起作用…我的目标是IOS 8.4。请提供您是如何尝试的?我一直在使用它,到目前为止没有遇到任何问题。hris.to,你有机会检查一下吗。仅供参考,我正在使用sendSynchronousRequest请求。未进行连接委派,您无法使用证书。请阅读本教程,了解如何通过委托方法实现连接。
func checkNetworkConnection(callback: ((isConnected: Bool) -> Void)!)
{
    var checkNetworkURL: String = “TESTURL”
    var request = NSMutableURLRequest(URL: NSURL(string: checkNetworkURL)!)

    request.HTTPMethod = "POST"
    request.addValue("application/xml", forHTTPHeaderField: "Content-Type")
    request.addValue("application/xml", forHTTPHeaderField: "Accept")
    request.timeoutInterval = 20000.0

    var response: NSURLResponse?
    var error: NSError?
    var data = NSURLConnection.sendSynchronousRequest(request, returningResponse: &response, error: &error)


        if error == nil{

            if data != nil{

                self.parser.getLoginResultDataDictionary(data!) {(dataDictionary) -> Void in
                    if let dataDict = dataDictionary[self.constants.defaultsKeys.RESPONSE_RESULT] as? Dictionary<String,String>
                    {
                        if let status: AnyObject  = dataDict[self.constants.defaultsKeys.RESPONSE_STATUS] {
                            if status as! String == self.constants.defaultsKeys.RESPONSE_SUCCESS {
                                callback(isConnected:  true)
                            }
                            else{
                                callback(isConnected:  false)
                            }
                        }
                        else{
                            callback(isConnected:  false)
                        }
                    }
                    else{
                        callback(isConnected:  false)
                    }
                }
            }
            else{
                callback(isConnected:  false)
            }
        }
        else{
            callback(isConnected:  false)
        }
    //}
     }
   public func connection(connection: NSURLConnection,  willSendRequestForAuthenticationChallenge challenge: NSURLAuthenticationChallenge)
{
    challenge.sender.useCredential(NSURLCredential(forTrust: challenge.protectionSpace.serverTrust), forAuthenticationChallenge: challenge)
    challenge.sender.continueWithoutCredentialForAuthenticationChallenge(challenge)
}
func connection(connection: NSURLConnection, willSendRequestForAuthenticationChallenge challenge: NSURLAuthenticationChallenge)
{
    challenge.sender.useCredential(NSURLCredential(forTrust: challenge.protectionSpace.serverTrust), forAuthenticationChallenge: challenge)
    challenge.sender.continueWithoutCredentialForAuthenticationChallenge(challenge)
}