Qubit
Qubit

Reputation: 69

WebClient downloads corrupted file in windows 8.1

I have a simple code that downloads a file from specified URL and it works great in windows 7, but when i run it in windows 8.1 downloaded file is corrupted. Where is the problem?

This is the code and URL:

WebClient wClient = new WebClient();
wClient.DownloadFile(@"http://members.tsetmc.com/tsev2/excel/MarketWatchPlus.aspx?d=0", "dl.xlsx");

Upvotes: 1

Views: 933

Answers (2)

Qubit
Qubit

Reputation: 69

Thanks to usr for help, i found the problem, server returns the file in GZip format so i have adapted the code:

public class WebDownload : WebClient
{
    protected override WebRequest GetWebRequest(Uri address)
    {
        HttpWebRequest request = (HttpWebRequest)base.GetWebRequest(address);
        if (request != null)
        {
            request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
        }
        return request;
    }
}

But still i dont know why my initial code runs without problem in my PC!

Upvotes: 2

usr
usr

Reputation: 171246

This URL does not deliver what you expect. Use Fiddler to find out what happens at the HTTP level. You need to find out what the server needs as input to respond with the correct content.

Upvotes: 1

Related Questions