验证 URL 时出现异常"The request was aborted: Could not create SSL/TLS secure channel"



我正在尝试验证C#代码中的URL,在Windows服务器2012R2服务器机器上遇到错误

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

我已经检查了通过网络中的各种帖子找到/得到的多个解决方案,但没有解决这个问题。

C#代码

public static bool isBrokenLink(string url, string KBid)
{
Boolean isBrokenLink = false;
try
{
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create(url);
webRequest.CookieContainer = new CookieContainer();
webRequest.AllowAutoRedirect = false;
webRequest.Timeout = 40000;
using (HttpWebResponse httpresponse = (HttpWebResponse)webRequest.GetResponse())
{
if (httpresponse.StatusCode == HttpStatusCode.OK)
{
isBrokenLink = false;
}
else if (httpresponse.StatusCode >= HttpStatusCode.Ambiguous && httpresponse.StatusCode <= HttpStatusCode.RedirectKeepVerb)
{
isBrokenLink = false;
}
else
{
isBrokenLink = true;
}
}
}
catch (Exception ex)
{
isBrokenLink = true;
}
return isBrokenLink;
}

在这台机器上,我安装了IE和Chrome浏览器。当我试图在IE 11浏览器中加载URL时,我也遇到了同样的错误。

当尝试使用URL签入chrome浏览器时,它可以正常工作。我还尝试在我的机器中将默认浏览器设置为chrome,并进行了检查。但仍然是同样的问题。有人知道这个问题吗?

我们可以修改代码以考虑使用chrome浏览器进行HttpWebResponse验证吗?

造成这种错误的原因有很多,而且提供的详细信息还不够。典型的问题是验证证书或TLS版本或支持的密码等。

一般来说:您的C#代码和IE使用内置在Windows中的相同TLS堆栈,而Chrome则自带TLS堆栈(BoringSSL(。将Chrome设置为默认浏览器不会神奇地取代OS TLS堆栈,即它仍然只由Chrome使用,而不是您的C#程序。

如果URL是公共的,你可以使用SSLabs来获取有关该网站的更多信息,该网站还显示了典型的问题以及与各种客户端的兼容性。这可能有助于你自己缩小问题的范围。

最新更新