![](/img/trans.png)
[英]C# HttpClient with X509Certificate2 - WebException: The request was aborted: Could not create SSL/TLS secure channel
[英]The request was aborted: Could not create SSL/TLS secure channel when using X509Certificate2
我有一个需要客户端证书身份验证的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策略错误?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.