gpt4 book ai didi

c# - 请求被中止 : Could not create SSL/TLS secure channel when using X509Certificate2

转载 作者:太空宇宙 更新时间:2023-11-03 14:26:02 37 4
gpt4 key购买 nike

我有一个需要客户端证书身份验证的 Web API,每当我提供正确的客户端证书时,我都会收到无法创建 SSL/TLS 安全通道的错误消息。

我的应用程序托管在我访问 API 的 IIS 服务器上。通过代码执行 API 时,我可以获得所需的结果,但是当应用程序托管在 IIS 上时,如果执行了请求,则会出现错误。

我的代码:

     myHttpWebRequest.ClientCertificates.Add(New X509Certificate2(certificate, myService.CertificateSettings.Certificate_Password.Decrypt))
Dim response = myHttpWebRequest.GetResponse()

可能是什么原因?

最佳答案

这可能很难解决 - 您可以使用以下代码忽略这些错误 - 不推荐...

   ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, errors) => {      
return true;
};

或者检查错误并尝试修复您的证书:

     ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, errors) =>
{
SslPolicyErrors result = errors;
Console.WriteLine(result);

};

您遇到了哪些 SSL 政策错误?

关于c# - 请求被中止 : Could not create SSL/TLS secure channel when using X509Certificate2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57162383/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com