请求已中止:无法创建SSL / TLS安全通道HttpClient

时间:2017-04-25 08:48:51

标签: c# api authentication ssl certificate

我正在尝试使用以下C#代码访问网络API:

private static CertificateContext authenticationContext;
authenticationContext = new CertificateContext(new Uri(endpoint), ThumbPrint);
var client = authenticationContext.GetHttpClient();
var response = await client.GetStringAsync(url);

最初工作正常,但后来我遇到错误:

The request was aborted: Could not create SSL/TLS secure channel.

我检查了一些论坛,并根据我在下面的选项中尝试的建议,但没有任何对我有用的

    1.ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
    2.ServicePointManager.ServerCertificateValidationCallback = delegate (object s, X509Certificate certificate, X509Chain chain, 
                SslPolicyErrors sslPolicyErrors) { return true; };

请帮我修复此错误。提前致谢

0 个答案:

没有答案