Last post Apr 21, 2010 03:24 AM by mikealbal
Jun 08, 2009 03:28 AM|SweeT EviL|LINK
I do something like that:
WebClient x = new WebClient();
How do I encode it from hebrew so that I wont see gibrish. I dont know if I need to encode the string that I send to the DownloadString function or if I need to dencode the returned string from gibrish to hebrew. Or even do both.
What do you suggest?
Jun 11, 2009 12:00 AM|Nai-Dong Jin - MSFT|LINK
WebClient internally uses a WebRequest to do the downloading; and it will use WebRequest.ContentType to search for "charset" header as the encoding.If the ContentType/charset header doesn't exist or contains invalid charset, WebClient.Encoding is used (which
is Encoding.Default by default or you can assign it before hand); however you should be aware that WebClient.Encoding is used as a fallback, if the response contains a valid encoding, it's always used to decode the returned data.
For a HttpWebRequest, the ContentType is from the HttpWebResponse. You can use Fiddler (http://www.fiddlertool.com/) to trace the http headers and see if WebClient used the correct Encoding to return the string.
Apr 21, 2010 03:24 AM|mikealbal|LINK
I have a similar problem. WebClient does not use the right encoding.
To fix the problem I use HttpWebRequest instead of WebClient.
On the following site you can find the code I use :
webclient asp.net localization