You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

仅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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.20 13:04:34