C# HttpClient请求https类型接口地址提示:未能创建 SSL/TLS 安全通道
在HttpClient建立连接前加上:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
ServicePointManager.ServerCertificateValidationCallback += RemoteCertificateValidate;
private static bool RemoteCertificateValidate(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors error)
{
return true;
}
本文介绍了解决C#中使用HttpClient请求HTTPS接口时遇到的“未能创建SSL/TLS安全通道”错误的方法。通过设置ServicePointManager的安全协议为Tls1.2,并自定义证书验证回调函数,可以有效避免这一问题。
1万+

被折叠的 条评论
为什么被折叠?



