Whenever I use WebClient.DownloadFile(), the resulting file length is always 0 bytes. I've tried files from different websites 开发者_开发知识库including my own IIS locally, always get a 0-byte length file. When clicking the filename in the browser (Chrome), the file downloads correctly.
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);
}
}
Am I doing something generally wrong, or can someone point me to a working example?
This code downloads a 5K file on my machine. I updated the filename and remoteUri values.
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);
精彩评论