Reputation: 1410
I have tried many methods to deserialise this xml from URL. But none were successful due to what I believe is an encoding issue.
If i right click download, then deserialise it from my C drive, it works fine.
So i decided to try downloading the file first, and then process it. But the file it downloads via code is in the wrong encoding as well!
I dont know where to start, but im thinking maybe forcing a UTF-8 or UTF-16 encoding when downloading??
Here is the download code:
using (var client = new WebClient())
{
client.DownloadFile("http://example.com/my.xml", "my.xml");
}
How to download a file from a URL in C#?
Upvotes: 0
Views: 1567
Reputation: 1410
The file was infact in a gzip format. Despite it being an xml url.
My connections must have been accepting gzip so the server responded with such. Even though i tried a few different methods with different variations. (Downloading/String streaming, parsing string from URL etc)
The solution for me, was to download, then uncompress the gzip file before deserialising. Telling the server not to send gzip didn't work. But may be a possibility for some.
Upvotes: 0
Reputation: 10071
Try this
using (var client = new WebClient())
{
client.Encoding = System.Text.Encoding.UTF8;
client.DownloadFile("http://example.com/my.xml", "my.xml");
}
Upvotes: 3