Alamofire - 证书固定测试 - 如何打印出原因

时间:2016-05-20 12:48:52

标签: ios swift alamofire

使用Alamofire 3.x,有没有办法打印出serverTrustPolicy失败的原因?目前,我手动将值从true更改为false以测试错误的证书。在这个例子中,我定义了一个错误的证书==自签名或不正确的主机名。

class PinningManager {

    var manager: Manager?

    init() {
        let serverTrustPolicies: [String: ServerTrustPolicy] = [
            "google.com": .PinCertificates(
                certificates: ServerTrustPolicy.certificatesInBundle(),
                validateCertificateChain: true,
                validateHost: true
            ),
            "httpbin.org": .DisableEvaluation
        ]

        manager = Alamofire.Manager(
            configuration: NSURLSessionConfiguration.defaultSessionConfiguration(),
            serverTrustPolicyManager: ServerTrustPolicyManager(policies: serverTrustPolicies)
        )
    }
}

0 个答案:

没有答案