CFNetwork SSLHandshake失败(-9806)&(-9800)&(-9830)

我正在使用AFNetworking(2.5)获取数据。 在这我也设置“setAllowInvalidCertificates:是”,但我仍然得到错误

CFNetwork SSLHandshake失败(-9806)

CFNetwork SSLHandshake失败(-9800)

CFNetwork SSLHandshake失败(-9830)

NSURLConnection / CFURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9830)

WebClientERROR:发生SSL错误,无法build立与服务器的安全连接。

看,我正在使用这个代码

AFSecurityPolicy *policy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone]; [policy setAllowInvalidCertificates:YES]; [op setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"JSON: %@", responseObject); if (completion) { completion([[UMWebResponse alloc] initWithJSON:responseObject]); } } failure:^(AFHTTPRequestOperation *operation, NSError *error) { if (completion) { if (operation.responseObject) { if (error.code == 401) { [APPDELEGATE showLoginViewController]; } completion([[UMWebResponse alloc] initWithJSON:operation.responseObject]); } else { if (error.code == 401) { [APPDELEGATE showLoginViewController]; } completion([[UMWebResponse alloc] initWithError:error]); } } }]; [[NSOperationQueue mainQueue] addOperation:op]; return op; 

您应该编辑您的服务器以支持TLSv1.2并保护您的http requests因为iOS 9OSX 10.11要求所有hosts都使用TLSv1.2 SSL

但在此期间,您可以在.plist文件中添加exception,如下所示:

 <key>NSAppTransportSecurity</key> <dict> <key>NSExceptionDomains</key> <dict> <key>yourserver.com</key> <dict> <!--Include to allow subdomains--> <key>NSIncludesSubdomains</key> <true/> <!--Include to allow insecure HTTP requests--> <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key> <true/> <!--Include to specify minimum TLS version--> <key>NSTemporaryExceptionMinimumTLSVersion</key> <string>TLSv1.1</string> </dict> </dict> </dict> 

如果你想处理每一个请求,只需在.plist添加这个条目:

 <key>NSAppTransportSecurity</key> <dict> <!--Connect to anything (this is probably BAD)--> <key>NSAllowsArbitraryLoads</key> <true/> </dict> 

资源