Ios CFNetwork SSLHandshake失败(-9806)&;(-9800)及;(-9830)
我正在使用AFNetworking(2.5)获取数据。我还设置了“setAllowInvalidCertificates:YES”,但仍然得到了错误 cf网络SSLHandshake失败(-9806) cf网络SSLHandshake失败(-9800) cf网络SSLHandshake失败(-9830) NSURLConnection/CFURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9830) WebClientERROR:发生SSL错误,并且安全连接到 无法创建服务器 看,我正在使用这个代码Ios CFNetwork SSLHandshake失败(-9806)&;(-9800)及;(-9830),ios,objective-c,ssl,afnetworking-2,Ios,Objective C,Ssl,Afnetworking 2,我正在使用AFNetworking(2.5)获取数据。我还设置了“setAllowInvalidCertificates:YES”,但仍然得到了错误 cf网络SSLHandshake失败(-9806) cf网络SSLHandshake失败(-9800) cf网络SSLHandshake失败(-9830) NSURLConnection/CFURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9830) WebClientERROR:发生SSL错误,并且
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请求作为iOS 9
和OSX 10.11
要求TLSv1.2 SSL
保护所有主机
但同时,您可以在.plist
文件中添加异常,如下所示:
<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>
<key>NSAppTransportSecurity</key>
<dict>
<!--Connect to anything (this is probably BAD)-->
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>