首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >DownloadFile已停止下载文件

DownloadFile已停止下载文件
EN

Stack Overflow用户
提问于 2019-03-29 19:07:00
回答 2查看 515关注 0票数 1

这个应用程序只是将一个新的exe文件下载到指定的路径,但是突然它不再工作了。更新程序下载大小为0kb的文件,并且不会给出任何错误。

2个月前,我将新的exe文件上传到服务器上,许多客户成功下载了该文件。昨天,我的一个客户注意到他开始使用应用程序,但更新失败了。该更新程序在许多客户端上运行,并且始终有效。会不会是服务器问题?

以下是C#中的更新器代码:

代码语言:javascript
复制
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文件,也没有更改过any服务器上的任何其他设置。

更新:

代码语言:javascript
复制
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
EN

回答 2

Stack Overflow用户

发布于 2019-03-29 19:33:37

您的服务器SSL证书似乎已损坏。可能已过期。如果您使用的是自签名证书,请确保导入了用于对服务器证书进行自签名的CA证书。另一种可能是您的服务器(或客户端)的系统时钟无效。所以客户端认为你的证书过期了。

票数 2
EN

Stack Overflow用户

发布于 2019-03-29 19:37:31

程序无法处理安全的uri。我添加了以下行

代码语言:javascript
复制
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;

在这条线下

代码语言:javascript
复制
webclient.DownloadFileCompleted += new AsyncCompletedEventHandler(webclient_DownloadFileCompleted);

解决了我的问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55416101

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档