c# - Encoding trouble with HttpWebResponse -


here snippet of code :

httpwebrequest webrequest = (httpwebrequest)webrequest.create(request.rawurl); webrequest.defaultwebproxy = null;//ensure not loop going again in proxy httpwebresponse response = (httpwebresponse)webrequest.getresponse(); string charset = response.characterset; encoding encoding; if (string.isnullorempty(charset)) encoding = encoding.default; else encoding = encoding.getencoding(charset);  streamreader resstream = new streamreader(response.getresponsestream(), encoding); return resstream.readtoend(); 

the problem if test : http://www.google.fr

all "é" not displaying well. have try change ascii utf8 , still display wrong. have tested html file in browser , browser display html text pretty sure problem in method use download html file.

what should change?

removed dead imageshack link

update 1: code , test file changed

firstly, easier way of writing code use streamreader , readtoend:

httpwebrequest webrequest = (httpwebrequest)webrequest.create(myurl); using (httpwebresponse response = (httpwebresponse)webrequest.getresponse()) {     using (stream resstream = response.getresponsestream())     {         streamreader reader = new streamreader(resstream, encoding.???);         return reader.readtoend();     } } 

then it's "just" matter of finding right encoding. how did create file? if it's notepad want encoding.default - that's not portable, it's default encoding your pc.

in well-run web server, response indicate encoding in headers. having said that, response headers claim 1 thing , html claims another, in cases.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -