C#WebClient下载图像失败

时间:2020-07-09 20:26:05

标签: c# .net webclient

我们从Windows Server 2012升级到Windows Server 2019。 我正在使用webclient在用户会话期间下载图像。 用于完美运行并在我运行时在本地运行。 当我将源代码移动到Windows Server 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尝试了同样的结果。

1 个答案:

答案 0 :(得分:3)

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

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

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