首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >请求已中止:无法创建SSL/TLS安全通道

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

Stack Overflow用户
提问于 2010-05-19 02:07:04
回答 32查看 1.1M关注 0票数 604

由于以下错误消息,我们无法使用WebRequest连接到HTTPS服务器:

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

我们知道服务器没有有效的HTTPS证书和使用的路径,但是为了绕过这个问题,我们使用了下面的代码,这些代码取自另一篇StackOverflow文章:

代码语言:javascript
复制
private void Somewhere() {
    ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(AlwaysGoodCertificate);
}

private static bool AlwaysGoodCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors policyErrors) {
   return true;
}

问题是服务器从未验证过证书,并失败并出现上述错误。有谁知道我该怎么做吗?

值得一提的是,我和一位同事几周前进行了测试,使用类似于我上面写的东西,它工作得很好。我们发现的唯一“主要区别”是我用的是Windows7,而他用的是Windows XP。这会改变什么吗?

EN

回答 32

Stack Overflow用户

发布于 2018-02-22 22:46:22

在.NET 4.5中,这个问题的解决方案是

代码语言:javascript
复制
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

如果您没有.NET 4.5,那么可以使用

代码语言:javascript
复制
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
票数 221
EN

Stack Overflow用户

发布于 2018-06-22 05:39:39

确保在创建HttpWebRequest之前进行了ServicePointManager设置,否则它将无法工作。

作品:

代码语言:javascript
复制
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
       | SecurityProtocolType.Tls11
       | SecurityProtocolType.Tls12
       | SecurityProtocolType.Ssl3;

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://google.com/api/")

失败:

代码语言:javascript
复制
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://google.com/api/")

ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
       | SecurityProtocolType.Tls11
       | SecurityProtocolType.Tls12
       | SecurityProtocolType.Ssl3;
票数 161
EN

Stack Overflow用户

发布于 2014-10-16 01:42:49

我在尝试访问https://ct.mob0.com/Styles/Fun.png时遇到了这个问题,这是一个由CloudFlare在其CDN上分发的图像,它支持像SPDY和奇怪的重定向SSL证书这样的疯狂东西。

我没有像在Simons answer中那样指定Ssl3,而是能够通过如下方式进入Tls12来修复它:

代码语言:javascript
复制
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
new WebClient().DownloadData("https://ct.mob0.com/Styles/Fun.png");
票数 42
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2859790

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档