从网页上读过来的html代码显示在控制台上是乱码,这个怎么解决?
从网页上读过来的html代码显示在控制台上是乱码,这个怎么解决?
下面是我读页面的代码:
/// <summary> /// 根据ulr读出html /// </summary> static string GetHtml(string url) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream stream = response.GetResponseStream(); StreamReader sReader = new StreamReader(stream, Encoding.Default); string html = sReader.ReadToEnd().Replace("\r\n", ""); response.Close(); Console.WriteLine(html); return html; }