【发布时间】:2020-05-06 05:45:57
【问题描述】:
我的目标是检查文件大小,我在几台 windows server 2012 r2 机器上测试了这段代码下面的代码给出了错误,(在所有这些机器上):
无法创建 SSL/TLS 安全通道
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
string url = @"https://www.gov.il/BlobFolder/reports/fortimail/he/FORTIMAIL-CERT-IL-W-1068.pdf";
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
using (HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse())
{
var headers = myHttpWebResponse.Headers;
string fileSize = "0";
if (headers.AllKeys.Contains("Content-Length"))
fileSize = headers.GetValues("Content-Length")[0];
Console.WriteLine(fileSize);
}
相同的代码在 Windows Server 2016 和 Windows 10 上运行良好,但在 Windows Server 2012 上却不行。
当我从 chrome 输入此链接时,它甚至可以在服务器 2012 上运行,对于邮递员,它也可以在所有机器上运行(但在 windows 2012 中不能通过代码运行)。
错误发生在给定的链接上,但对于其他文件网址,如http://www.orimi.com/pdf-test.pdf,它可以正常工作。
我也尝试通过注册表启用 TLS:
有什么想法吗?
【问题讨论】:
-
有一些 Windows 更新完全支持 TLS1.2,例如support.microsoft.com/en-us/help/3140245/…。您的屏幕截图适用于 TLS1.1 设置,因此显然要仔细检查您的注册表设置。还有哪些密码是允许的……也许你没有启用它们?例如dirteam.com/sander/2019/07/30/…
-
@boby 尝试我的答案中解释的解决方案,让我知道它是否有效。
标签: ssl tls1.2 windows-server-2012 windows-server-2012-r2