我使用AFNetworking(2.5)获取数据。在那我也设置“setAllowInvalidCertificates:YES”,但我仍然得到错误
CFNetwork SSLHandshake失败(-9806)
CFNetwork SSLHandshake失败(-9800)
CFNetwork 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;
答案 0 :(得分:1)
您应该修改服务器以支持TLSv1.2
并保护http requests
iOS 9
OSX 10.11
TLSv1.2 SSL
hosts
所有.plist
。< / p>
但与此同时,您可以在<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>
:
{{1}}