【发布时间】:2020-03-10 06:50:01
【问题描述】:
我正在尝试在 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# ssl .net-4.5 tls1.2 windows-server-2012-r2