仅Windows设备无法建立SSL连接,macOS运行正常的问题求助
仅Windows设备无法建立SSL连接,macOS运行正常的问题求助
我最近碰到个头疼的问题:用下面的代码调用API接口时,只有在Windows系统上会抛出SSL连接失败的错误,但在macOS上跑完全正常,能顺利拿到正确的数据。
错误信息如下:
System.Net.Http.HttpRequestException: 'The SSL connection could not be established, see inner exception.' AuthenticationException: Authentication failed, see inner exception.
我的代码是这样的:
var handler = new HttpClientHandler { ClientCertificateOptions = ClientCertificateOption.Manual, SslProtocols = SslProtocols.Tls12, ServerCertificateCustomValidationCallback = (e, r, c, n) => true, }; handler.ClientCertificates.Clear(); handler.ClientCertificates.Add(new X509Certificate2(@"cert.pfx", "xxx")); var client = new HttpClient(handler); ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12; ServicePointManager.Expect100Continue = true; var result = await client.GetAsync("https://some_url.com/some_method"); var tmp = result.Content.ReadAsStringAsync();
想问下有没有懂的朋友,是不是Windows系统上需要做什么特殊配置才能让这段代码正常运行呀?
备注:内容来源于stack exchange,提问作者cristianormoraes
相关产品推荐
相关产品推荐

