AFNetworking访问https出现"NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9806"

       在之前一篇博客中《AFNetworking访问https出现"NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813"》,而在这篇博客中的这个bug也是非常的类似。出现的场景也是服务端使用了自签名的证书,然后客户端按照《AFNetworking访问https出现"NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813"》中的方式生成client.cer文件,并导入到Build Phases中的“Copy Bundle Resources”中,在AFNetworking中的请求中也加了如下代码:

    AFSecurityPolicy * securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate];
    securityPolicy.allowInvalidCertificates = YES;
    securityPolicy.validatesDomainName = NO;

    manager.securityPolicy = securityPolicy;

    但是网络请求过程中仍然出现标题中的bug:

NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9806)
Printing description of error:
Error Domain=NSURLErrorDomain Code=-1200 "An SSL error has occurred and a secure connection to the server cannot be made." UserInfo={_kCFStreamErrorCodeKey=-9806, NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, NSUnderlyingError=0x608000256c50 {Error Domain=kCFErrorDomainCFNetwork Code=-1200 "(null)" UserInfo={_kCFStreamPropertySSLClientCertificateState=0, _kCFNetworkCFStreamSSLErrorOriginalValue=-9806, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9806}}, NSLocalizedDescription=An SSL error has occurred and a secure connection to the server cannot be made., NSErrorFailingURLKey=https://118.178.126.250:8001/v1_0/user/customer/register?phone=13&password=c51ce410c124a10e0db5e4b97fc2af39, NSErrorFailingURLStringKey=https://118.178.126.250:8001/v1_0/user/customer/register?phone=13&password=c51ce410c124a10e0db5e4b97fc2af39, _kCFStreamErrorDomainKey=3}

截图如下:



这是因为iOS的https新的政策导致的,需要我们去Info.plist中去进行设置,新增以下两项:



你可能感兴趣的:(ios,https,AFNetworking)