每当我使用WebClient.DownloadFile()时,生成的文件长度始终为0字节.我尝试过来自不同网站的文件,包括我自己的本地IIS,总是得到一个0字节长的文件.在浏览器(Chrome)中单击文件名时,文件会正确下载.
string fileName = @"us_ysera_tier11.json.gz";
string remoteUri = @"http://wowprogress.com/exports/ranks/" + fileName;
if (!File.Exists(fileName))
{
using (WebClient webClient = new WebClient())
{
webClient.UseDefaultCredentials = true;
webClient.DownloadFile(remoteUri, fileName);
}
}
Run Code Online (Sandbox Code Playgroud)
我做了一些普遍错误的事情,或者有人能指出我一个有效的例子吗?
此代码在我的机器上下载一个5K文件.我更新了文件名和remoteUri值.
string fileName = "us_ysera_tier11.json.gz";
string remoteUri = "http://www.wowprogress.com/export/ranks/" + fileName;
WebClient webClient = new WebClient();
webClient.Headers["Accept-Encoding"] = "application/x-gzip";
webClient.DownloadFile(remoteUri, fileName);
Run Code Online (Sandbox Code Playgroud)