Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios CFNetwork SSLHandshake失败(-9806)&;(-9800)及;(-9830)_Ios_Objective C_Ssl_Afnetworking 2 - Fatal编程技术网

Ios CFNetwork SSLHandshake失败(-9806)&;(-9800)及;(-9830)

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错误,并且

我正在使用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>