【发布时间】:2019-08-20 07:35:23
【问题描述】:
我有一个更新应用程序,当有可用更新时它正在启动。此应用程序只是将新的 exe 下载到指定路径,但突然它不再工作了。更新程序下载的文件大小为0kb,没有报错。
我在 2 个月前将新的 exe 上传到服务器,许多客户成功下载了该文件。昨天,我的一位客户注意到他开始使用该应用程序并且更新失败。更新程序在许多客户端上运行并且始终有效。会不会是服务器问题?
这是 C# 中的更新程序代码:
public void StartUpdate()
{
WebClient webclient = new WebClient();
try
{
//webclient.DownloadFile("http://www.example.nl/folder/example.exe", @"C:\example\example.exe");
webclient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(webclient_DownloadProgressChanged);
webclient.DownloadFileCompleted += new AsyncCompletedEventHandler(webclient_DownloadFileCompleted);
webclient.DownloadFileAsync(new Uri("http://www.example.nl/folder/example.exe"), @"C:\example\example.exe");
}
catch (Exception)
{
MessageBox.Show("Download Failed.\n\nPlease contact your system administrator");
Application.Exit();
}
}
void webclient_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
label1.Text = "Download successfully!";
label3.Text = "Download complete!";
timer2.Enabled = true; //here some other magic happens like start the program and exit this updater.
}
void webclient_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
progressBar1.Maximum = (int)e.TotalBytesToReceive / 100;
progressBar1.Value = (int)e.BytesReceived / 100;
}
我在存储 exe 文件的 CentOS 上运行 Apache。文件夹/文件权限没问题。当我在任何浏览器中打开 exe URL 时,文件已成功下载。 在过去的 2 个月内,我从未更改过 exe 文件,也从未更改过网络服务器上的任何其他设置。这个方法用了2年,现在自动失效了。
更新:
System.Net.WebException: The request has been aborted: Cannot create a secure SSL / TLS channel.
at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult)
at System.Net.WebClient.GetWebResponse (WebRequest request, IAsyncResult result)
at System.Net.WebClient.DownloadBitsResponseCallback (IAsyncResult result) A first chance exception or type 'System.ComponentModel.Win32Exception' occurred in System.dll
【问题讨论】:
-
我在不同的机器上测试了这个,它不再在所有机器上工作了......
-
我敢打赌服务器现在需要 TLS1.2。这并不是什么新鲜事,自 2016 年以来每个人都在转向 TLS1.2 和 HeartBleed。早在 2016 年,航空公司就放弃了对低于 TLS1.2 的任何东西的支持。谷歌、Azure、亚马逊、银行等已经宣布他们多年来将放弃对低于 TLS1.2 的任何东西的支持。
标签: c# webclient downloadfile downloadfileasync