Setting encoding when retrieving webpage

Malfunction

Junior Contributor
Joined
Dec 8, 2003
Messages
203
Location
Berlin, Germany
hello,

im using this snippet to get the sourcecode of a webpage:

Code:
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(this.currentURL);     
            WebResponse response = myReq.GetResponse();
            StreamReader reader = new StreamReader(response.GetResponseStream());
            String source = reader.ReadToEnd();
            reader.Close();
            response.GetResponseStream().Close();
            this.sourcebox.Text = source;

i guess that's pretty dirty but it works (almost).
trouble is that the encoding is not correct. if the webpage's charset is utf-8 the non asci characters are not shown in the textbox.

sorry for posting nubee questions again but i couldn't find a read to use snippet on the net.
 
Back
Top