首页 > 代码库 > AFNetworking访问https出现"NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9806"
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:
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=http://www.mamicode.com/-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"
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。