简体   繁体   English

c# webclient 下载镜像失败

[英]c# webclient download image fail

We upgraded from windows server 2012 to windows server 2019. I'm using webclient to download images during a user session.我们从 windows 服务器 2012 升级到 windows 服务器 2019。我正在使用 webclient 在用户 session 期间下载图像。 Use to work perfectly and works locally when I run it.当我运行它时,它可以完美地工作并在本地工作。 When I move the source code to windows server 2019 it fails with the standard The underlying connection was closed:当我将源代码移动到 windows 服务器 2019 时,它因标准而失败底层连接已关闭:

Using.Net 4.6 Using Security Protocol Tls12. Using.Net 4.6 使用安全协议 Tls12。 I'm extremely baffled by what is causing the issue我对导致问题的原因感到非常困惑

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

Does anyone have some other suggestions.有没有人有一些其他的建议。 I tried with Exter100Continue = true with same results.我尝试使用 Exter100Continue = true 得到相同的结果。

There are some big changes in the versions and cipher suites from 2012 to 2019.从 2012 年到 2019 年,版本和密码套件发生了一些重大变化。

First: I would recommend that you just allow the OS to decide which Security Protocol to use (it will negotiate TLS version and cipher suite with the server that hosts your image).首先:我建议您只允许操作系统决定使用哪个安全协议(它将与托管您的图像的服务器协商 TLS 版本和密码套件)。 Here is a good article about TLS versioning and .NET versions and OS versions这是一篇关于 TLS 版本控制和 .NET 版本和操作系统版本的好文章

Second: I would run something like Fiddler locally on your server to see where the web request is failing (I'm guessing the TLS handshake fails).第二:我会在您的服务器上本地运行类似Fiddler的东西,以查看 web 请求失败的位置(我猜 TLS 握手失败)。 Fiddler will provide alot more detail about your web requests at the packet level. Fiddler 将在数据包级别提供有关您的 web 请求的更多详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM