c# webclient 下载图片失败

c# webclient download image fail

我们从 windows 服务器 2012 升级到 windows 服务器 2019。 我正在使用 webclient 在用户会话期间下载图像。 当我 运行 它时,使用它可以完美地工作并在本地工作。 当我将源代码移动到 windows 服务器 2019 时,它失败并显示标准 基础连接已关闭:

使用 .Net 4.6 使用安全协议 Tls12。 我对导致问题的原因感到非常困惑

                ServicePointManager.Expect100Continue = false;
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
                using (var web_client = new WebClient())
                {
                web_client.DownloadFile(file_url, download_file_path_with_name);
                }    

有没有人有一些其他的建议。我尝试使用 Exter100Continue = true 得到相同的结果。

从 2012 年到 2019 年,版本和密码套件发生了一些重大变化。

首先: 我建议您只允许 OS 决定使用哪个安全协议(它将与托管您的图像的服务器协商 TLS 版本和密码套件)。这是一个good article about TLS versioning and .NET versions and OS versions

第二个: 我会在您的服务器上 运行 类似 Fiddler 的本地内容,以查看 Web 请求失败的位置(我猜 TLS 握手失败)。 Fiddler 将在数据包级别提供有关您的 Web 请求的更多详细信息。