I downloaded some web pages use System.Net.HttpWebResponse,and get string
from it
Like this:
webresponse = (System.Net.HttpWebResponse)req.GetResponse();
System.IO.StreamReader stream = new System.IO.StreamReader
(webresponse.GetResponseStream(),Encoding.GetEncod ing("utf-8"));
string content = stream.ReadToEnd();
, but the page I downloaded may not encoded in "utf-8" , so I parse these
page to
get the right encoding, and convert string's encoding ,Like this:
Encoding oldEnc = Encoding.GetEncoding(oldEncoding);
Encoding rightEnc = Encoding.GetEncoding(_encoding);
temp = rightEnc.GetBytes(content);
byte[] asciiBytes = Encoding.Convert(oldEnc,rightEnc,temp);
// Convert the new byte[] into a char[] and then into a string.
// This is a slightly different approach to converting to illustrate
// the use of GetCharCount/GetChars.
char[] asciiChars = new char[rightEnc.GetCharCount(asciiBytes, 0,
asciiBytes.Length)];
rightEnc.GetChars(asciiBytes, 0, asciiBytes.Length, asciiChars, 0);
string asciiString = new string(asciiChars);
But I just get something can't be understood£¬why? What should I do?
The page I used to test is encoded in "gb2312"
Thanks for your read.