为什么它在消息框上显示问号而不是文本
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://teamxor.net/vb/tx48/"+ page);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream());
string result = sr.ReadToEnd();
Regex r = new Regex("<div>.*?</div>");
MatchCollection mr = r.Matches(result);
foreach (Match m in mr)
{
MessageBox.Show(m.Value, "Test", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading);
}
问题在于使用非默认代码页。您的HTML显示您正在使用代码页1256。您必须告诉.NET,否则它认为它是UTF-8:
StreamReader sr = new StreamReader( response.GetResponseStream()
, Encoding.GetEncoding(1256) // <-- this one
);
使用Encoding.GetEncoding
得到正确的代码页。我建议改用UTF8,因为.NET很容易识别。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句