Alamofire使用PinCertificates请求始终失败并取消(代码= -999)

时间:2015-10-14 09:24:50

标签: swift https alamofire

以这种方式使用Alamofire来解决问题:

let serverTrustPolicies: [String: ServerTrustPolicy] = [
        "localhost": .PinCertificates(
            certificates: ServerTrustPolicy.certificatesInBundle(),
            validateCertificateChain: true,
            validateHost: true
        )]
let configue = NSURLSessionConfiguration.defaultSessionConfiguration()
configue.HTTPAdditionalHeaders = Manager.defaultHTTPHeaders

mrg = Manager(
        configuration: configue,
        serverTrustPolicyManager: ServerTrustPolicyManager(policies: serverTrustPolicies))

mrg!.request(.GET, "https://localhost/Demo/products.php", parameters: nil, encoding: .URL, headers: nil).responseJSON { 
        guard let res = $0.result.value where res is NSArray else { print("error"); return; } 
        self.json = JSON(res)
    }

然后错误域= NSURLErrorDomain代码= -999"取消"。

它是如何发生的?哪里错了?

alamofire源代码没有任何变化。

谢谢你的回答!

0 个答案:

没有答案