NSURLSession / NSURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9825)错误域= NSURLErrorDomain代码= -1205

时间:2017-01-05 07:39:59

标签: ios https afnetworking

NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9825)
Error Domain=NSURLErrorDomain Code=-1205 "服务器“10.100.5.105”不接受证书。" UserInfo={NSURLErrorFailingURLPeerTrustErrorKey=<SecTrustRef: 0x1701042f0>, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9825, NSUnderlyingError=0x17024dc80 {Error Domain=kCFErrorDomainCFNetwork Code=-1205 "(null)" UserInfo={_kCFStreamPropertySSLClientCertificateState=1, kCFStreamPropertySSLPeerTrust=<SecTrustRef: 0x1701042f0>, _kCFNetworkCFStreamSSLErrorOriginalValue=-9825, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9825, kCFStreamPropertySSLPeerCertificates=(
    "<cert(0x101973200) s: taxappbs i: taxappca>"
)}}, NSErrorPeerCertificateChainKey=(
    "<cert(0x101973200) s: taxappbs i: taxappca>"
), NSLocalizedDescription=服务器“10.100.5.105”不接受证书。, NSErrorFailingURLKey=https://10.100.5.105:6443/entry, NSErrorFailingURLStringKey=https://10.100.5.105:6443/entry, NSErrorClientCertificateStateKey=1}

我使用httpsAFNetworking 3.x服务器请求证书。它告诉我服务器拒绝了证书。任何人都知道如何解决它?

&#34;服务器&#34; =&#34;服务器&#34;

&#34;不接受证书&#34; =&#34;拒绝证书&#34;

private static let manager: AFHTTPSessionManager = {
        let config = URLSessionConfiguration.default
        config.timeoutIntervalForRequest = 10
        let manager = AFHTTPSessionManager(sessionConfiguration: config)
        manager.requestSerializer = AFJSONRequestSerializer(writingOptions: .prettyPrinted)
        manager.responseSerializer = AFJSONResponseSerializer(readingOptions: .allowFragments) // AFHTTPResponseSerializer()
        manager.responseSerializer.acceptableContentTypes = ["application/json", "text/json", "text/JavaScript", "text/html", "text/plain", "image/png"]
        let policy = AFSecurityPolicy(pinningMode: .certificate)
        policy.allowInvalidCertificates = true
        policy.validatesDomainName = false
        policy.pinnedCertificates = AFSecurityPolicy.certificates(in: .main)
        manager.securityPolicy = policy
        return manager
    }()

这是我的代码。

1 个答案:

答案 0 :(得分:0)

您的应用服务器应支持TLS 1.2。因为在iOS 11+上,HTTPS使用TLSv1.2握手并创建HTTP会话。配置服务器的Tomcat或Nginx以接受TLSv1.2。