我正在尝试验证C#代码中的URL,并且在Windows Server 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验证吗?
[通常:您的C#代码和IE使用Windows内置的同一TLS堆栈,而Chrome附带其自己的TLS堆栈(BoringSSL)。将Chrome设置为默认浏览器不会神奇地替换OS TLS堆栈,即它仍将仅由Chrome使用,而不由您的C#程序使用。
如果URL是公共的,则可以使用SSLLabs获取有关此站点的更多信息,该站点还显示典型的问题以及与各种客户端的兼容性。这可以帮助您自己缩小问题的范围。