码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2017-03-06 12:36:34      阅读:2672      评论:0      收藏:0      [点我收藏+]

标签:awd   xdg   exp   sasl   ddr   awr   pps   dos   webx   

       在之前一篇博客中《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中去进行设置,新增以下两项:

技术分享


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

标签:awd   xdg   exp   sasl   ddr   awr   pps   dos   webx   

原文地址:http://blog.csdn.net/chenyufeng1991/article/details/60489312

(1)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!