用webbroswer控件获取网页内容时,中文经常会出现乱码,因为.net用的编码格式unicode,但是网页有的是gb2312,月的用的是utf-8,这就导致中文乱码。解决办法:
System.IO.StreamReader getReader = new System.IO.StreamReader(this.Webbroswer.DocumentStream, System.Text.Encoding.GetEncoding("UTF-8")); //这里的utf-8,可以换成其他的编码格式,也可以用 this.webBrowser.Document.Encoding
string gethtml = getReader.ReadToEnd();
搞定。
本文介绍了解决使用Webbrowser控件时遇到的中文乱码问题的方法。通过设置正确的编码方式来确保从网页获取的内容能正确显示中文字符。
579

被折叠的 条评论
为什么被折叠?



