1

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?

Cokegod
  • 8,256
  • 10
  • 29
  • 47
  • 2
    What do you mean with 'gibberish' ? Post a sample along with what it should be. – H H Feb 17 '12 at 21:16
  • gibberish? how? your code returns same data. – L.B Feb 17 '12 at 21:18
  • 2
    I ran following code: `WebClient wc = new WebClient(); string st = wc.DownloadString(@"http://thetvdb.com/api/C40F55BF6975A295/series/80379/default/5/16/en.xml");` and it returned XML as expected – Raj Ranjhan Feb 17 '12 at 21:23
  • Strange, for me everything works fine for the file you give: `Console.WriteLine(XDocument.Parse(new WebClient().DownloadString(xml_file_address_here))); // np` – user1096188 Feb 17 '12 at 21:24

2 Answers2

3

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.

Community
  • 1
  • 1
Bruno Silva
  • 3,077
  • 18
  • 20
0

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.

Sean H
  • 736
  • 6
  • 9