Cokegod
Cokegod

Reputation: 8424

Downloading an XML file as string in C# keeps getting me gibberish

So in my C# application I am downloading an XML file as a string, then doing something with it. Some files are downloaded correctly, but for some files I get gibberish. The weird thing is that when I open those files with my browser (Firefox) I get the data as I should, and not the gibberish.

This is my code to download the data:

public static string Read(string Address)
{
    return new WebClient().DownloadString(Address);
}

And this is an example of a file I get gibberish when downloading: http://thetvdb.com/api/C40F55BF6975A295/series/80379/default/5/16/en.xml

So how can I get the data for these files?

Upvotes: 1

Views: 1095

Answers (2)

Sean H
Sean H

Reputation: 746

I'm not sure, but it could be an encoding issue. You may want to download the content from the web resource as binary data, and pump it into an XML reader.

Upvotes: 0

Bruno Silva
Bruno Silva

Reputation: 3097

I think you are downloading the gzipped version of the xml file. Firefox decompresses that automatically for you.

Have a look at Uncompressing gzip response from WebClient to do the same with WebClient.

Upvotes: 3

Related Questions