DownloadFile creates 0-byte files

Whenever I use WebClient.DownloadFile (), the resulting file length is always 0 bytes. I tried files from different sites, including my own IIS locally, I always get a file with a length of 0 bytes. When you click on the file name in the browser (Chrome), the file loads 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 wrong at all, or can someone point me to a working example?

+3
source share
1 answer

This code downloads a 5K file on my computer. I updated the file name 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);
+5
source

All Articles