WebClient DownloadFileAsync() 工作不正确
WebClient DownloadFileAsync() work Incorect
我使用WebClient
从服务器下载文件,但下载的文件不一样(文件大小不对):
截图如下(右边是下载的文件):
这是我的代码:
public void StartDownload(string fileToDownloadLink, string PathToSaveFile) ///////// Try check file type..
{
try
{
using (webClient = new WebClient())
{
//webClient.Encoding = Encoding.UTF8;
webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Client_DownloadFileCompleted);
webClient.DownloadFileAsync(new Uri(fileToDownloadLink), PathToSaveFile);
}
}
catch (WebException e)
{
MessageBox.Show(fileToDownloadLink);
MessageBox.Show(e.ToString());
Worker.CancelAsync();
Application.Exit();
}
}
怎么了?
我大概找到了为什么会这样。服务器仅支持 ASCII 编码查看上传到服务器后的文件大小:
enter image description here
我强制编码并且成功了:)现在文件是一样的:)
我使用WebClient
从服务器下载文件,但下载的文件不一样(文件大小不对):
截图如下(右边是下载的文件):
这是我的代码:
public void StartDownload(string fileToDownloadLink, string PathToSaveFile) ///////// Try check file type..
{
try
{
using (webClient = new WebClient())
{
//webClient.Encoding = Encoding.UTF8;
webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Client_DownloadFileCompleted);
webClient.DownloadFileAsync(new Uri(fileToDownloadLink), PathToSaveFile);
}
}
catch (WebException e)
{
MessageBox.Show(fileToDownloadLink);
MessageBox.Show(e.ToString());
Worker.CancelAsync();
Application.Exit();
}
}
怎么了?
我大概找到了为什么会这样。服务器仅支持 ASCII 编码查看上传到服务器后的文件大小: enter image description here
我强制编码并且成功了:)现在文件是一样的:)