var handler = new HttpClientHandler();
handler.ClientCertificateOptions = ClientCertificateOption.Manual;
handler.ServerCertificateCustomValidationCallback =
(httpRequestMessage, cert, cetChain, policyErrors) =>
{
return true;
};
var client = new HttpClient(handler);
HttpClient 访问https地址抛异常:The SSL connection could not be established, see inner exception
HTTPS客户端证书验证配置
最新推荐文章于 2025-09-28 12:45:42 发布
这段代码演示了如何在HTTP客户端中手动设置证书选项,并且忽略服务器证书的验证,用于HTTPS连接。通过设置`ClientCertificateOptions`为`Manual`,可以指定客户端证书,而`ServerCertificateCustomValidationCallback`回调函数则允许所有证书。
803





