ios - CFNetwork SSLHandshake 失败 (-9806) & (-9800) & (-9830)
<p><p>我正在使用 AFNetworking(2.5) 获取数据。因为我还设置了“setAllowInvalidCertificates:YES”,但我仍然收到错误</p>
<p><strong>CFNetwork SSLHandshake 失败 (-9806)</strong></p>
<p><strong>CFNetwork SSLHandshake 失败 (-9800)</strong></p>
<p><strong>CFNetwork SSLHandshake 失败 (-9830)</strong></p>
<p><strong>NSURLConnection/CFURLConnection HTTP 加载失败(kCFStreamErrorDomainSSL,-9830)</strong></p>
<blockquote>
<p>WebClientERROR: An SSL error has occurred and a secure connection to
the server cannot be made.</p>
</blockquote>
<p>看,我正在使用此代码</p>
<pre><code>AFSecurityPolicy *policy = ;
;
[op setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@", responseObject);
if (completion) {
completion([ initWithJSON:responseObject]);
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
if (completion) {
if (operation.responseObject) {
if (error.code == 401) {
;
}
completion([ initWithJSON:operation.responseObject]);
} else {
if (error.code == 401) {
;
}
completion([ initWithError:error]);
}
}
}];
[ addOperation:op];
return op;
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您应该编辑您的服务器以支持 <code>TLSv1.2</code> 并将您的 <code>http 请求</code> 保护为 <code>iOS 9</code> 和 <code>OSX 10.11</code> 要求所有 <code>hosts</code> 的 <code>TLSv1.2 SSL</code>。</p>
<p>但与此同时,您可以像这样在 <code>.plist</code> 文件中添加异常:</p>
<pre><code><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>
</code></pre>
<p>如果您想处理每个请求,只需在 <code>.plist</code> 中添加此条目:</p>
<pre><code><key>NSAppTransportSecurity</key>
<dict>
<!--Connect to anything (this is probably BAD)-->
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
</code></pre>
<p> <a href="http://jeffgukang.com/archives/208" rel="noreferrer noopener nofollow">source</a> </p></p>
<p style="font-size: 20px;">关于ios - CFNetwork SSLHandshake 失败 (-9806) & (-9800) & (-9830),我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/31400533/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/31400533/
</a>
</p>
页:
[1]