我使用下面的代码来保存一个 utf-8 网页:
HttpWebRequest myWebRequest = (HttpWebRequest) WebRequest.Create(txtUrl.Text);
myWebRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1);Accept-Language:fa";
WebResponse myWebResponse = myWebRequest.GetResponse();
Stream ReceiveStream = myWebResponse.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
StreamReader readStream = new StreamReader(ReceiveStream, encode);
string strResponse = readStream.ReadToEnd();
StreamWriter oSw = new StreamWriter(@"c:\ehsan.html");
oSw.WriteLine(strResponse);
oSw.Close();
readStream.Close();
myWebResponse.Close();
txtUrl.Text = strResponse;
但在 ehsan.html 文件和 txtUrl 中,所有 unicode 字符都是符号。我的解决方案是否正确?有谁有想法吗?