ios 获取 CFNetwork SSLHandshake 失败 (-9806) 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20244815/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 22:31:55  来源:igfitidea点击:

Getting CFNetwork SSLHandshake failed (-9806) error

iosobjective-c

提问by Jay Gajjar

I am trying to call my url using

我正在尝试使用

NSDictionary *landingDetails=[appDelegate landingPage];

        NSString *devinf=[UIDevice currentDevice].systemVersion;
        NSString *appVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];

        NSMutableDictionary *reqDict=[NSMutableDictionary dictionary];
        [reqDict setObject:@"refillByScan" forKey:@"appId"];
        [reqDict setObject:@"extest1" forKey:@"affId"];
        [reqDict setObject:[landingDetails objectForKey:@"token"] forKey:@"token"];
        [reqDict setObject:@"0124400-59382" forKey:@"rxNo"];//medication or prescription id
        [reqDict setObject:@"appName://handleControlFromScanRefill" forKey:@"appCallBackScheme"];
        [reqDict setObject:@"callBackAction" forKey:@"appCallBackAction"];
        [reqDict setObject:@"chkExpRx" forKey:@"act"];
        [reqDict setObject:@"" forKey:@"trackingId"];
        [reqDict setObject:devinf forKey:@"devinf"];
        [reqDict setObject:appVersion forKey:@"appver"];

        NSString *landingUrl=[landingDetails objectForKey:@"landingUrl"];//my url
        request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:landingUrl]];
        NSString *jsonRequest = [reqDict JSONRepresentation];
        NSLog(@"jsonRequest is %@", jsonRequest);
        NSData *requestData = [NSData dataWithBytes:[jsonRequest UTF8String] length:[jsonRequest length]];

        [request setHTTPMethod:@"POST"];
        [request setValue:[NSString stringWithFormat:@"%d", [requestData length]] forHTTPHeaderField:@"Content-Length"];
        [request setHTTPBody: requestData];

        con=[[NSURLConnection alloc]initWithRequest:request delegate:self];
        [con start];

I am getting this error in my log

我在日志中收到此错误

2013-11-27 19:43:30.754 WallGreen[5594:3a03] CFNetwork SSLHandshake failed (-9806)
2013-11-27 19:43:31.273 WallGreen[5594:3a03] CFNetwork SSLHandshake failed (-9806)
2013-11-27 19:43:31.799 WallGreen[5594:3a03] CFNetwork SSLHandshake failed (-9806)
2013-11-27 19:43:31.800 WallGreen[5594:3a03] NSURLConnection/CFURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9806)

回答by Arkaaito

FWIW: I got the same error number and it was due to an expired certificate, so this is another potential source for the issue.

FWIW:我得到了相同的错误号,这是由于证书过期,所以这是该问题的另一个潜在来源。

回答by sarge

There is a bug on iOS 8 when using a certificate with hash function SHA512, better use the SHA256. I stuck with this error for weeks.

在 iOS 8 上使用带有哈希函数 SHA512 的证书时存在一个错误,最好使用 SHA256。我被这个错误困扰了好几个星期。

回答by Usman Javed

Normally when I get CFNetwork SSLHandshake failed -(*) Its because of my local wifi network (device is connected to network but not the internet)

通常当我得到 CFNetwork SSLHandshake 失败 -(*) 这是因为我的本地 wifi 网络(设备已连接到网络但未连接到互联网)

Try it again on another network (3G is the quickest solution for me)

在另一个网络上再试一次(3G 对我来说是最快的解决方案)