0

I made a code so download a page so uses the chunked encoding, but the result is not good - a ����� characters.

I looked at fiddler - there the characters are correct.

How can I get the correct characters with keeping stuff simple? (no manual parsing)

Or - how can I tell to the server so we not support this encoding?

Thanks in advance

Here is the code in C#

HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create("http://www.grad-nk.ru/arti/531.php"); var webResponse = (HttpWebResponse)webRequest.GetResponse(); using (Stream stream = webResponse.GetResponseStream()) { using (StreamReader streamReader = new StreamReader(stream)) { var content = streamReader.ReadToEnd(); } } 

Edit:

Here is the line so makes it work

using (StreamReader streamReader = new StreamReader(stream, Encoding.GetEncoding(webResponse.CharacterSet))) 

Thanks to wal!!!

1
  • 1
    Is there are charset specified in the Content-Type header of the response? Commented Mar 1, 2012 at 14:10

1 Answer 1

2

The Content-Type of that page is windows-1251 so you will have to use that Encoding when reading the response from the stream.

Change this line in your code:

using (StreamReader streamReader = new StreamReader(stream)) 

to this:

using (StreamReader streamReader = new StreamReader(stream, Encoding.GetEncoding(1251))) 

which will fix your problem.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.