Home > Uncategorized > Retrieving web pages with foreign characters

Retrieving web pages with foreign characters

When you make a request to a web page using code such as:

HttpWebRequest httprequest = (HttpWebRequest)WebRequest.Create(requestURI);
HttpWebResponse
httpresponse = (HttpWebResponse)httprequest.GetResponse();
Stream responsestream = httpresponse.GetResponseStream();
StreamReader httpstream = new StreamReader(responsestream);
string bodytext = httpstream.ReadToEnd();

You may find that certain characters may be missing from the string returned, such as the copyright © character, or foreign characters, such as é (e acute). In order to get around this you need to use Latin encoding (ISO 8859) in the StreamReader thus:

StreamReader httpstream =

new StreamReader(responsestream, Encoding.GetEncoding("iso8859-1"));

… had me stumped for ages!

Advertisements
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: