我正在尝试使用System.windows.Forms.WebBrowser
以以外的语言显示内容,但结果编码不正确。我该怎么做才能显示俄罗斯?
我正在下载并显示如下字符串:
System.Net.WebClient wc = new System.Net.WebClient();
webBrsr.DocumentText = wc.DownloadString(url);
答案 0 :(得分:1)
问题在于WebClient
以及它如何解释字符串编码。一种解决方案是将数据作为原始字节下载并手动解析:
Bytes[] bytes = wc.DownloadData("http://news.google.com/news?edchanged=1&ned=ru_ru");
//You should really inspect the headers from the response to determine the exact encoding to use,
// this example just assumes UTF-8 which might work in most scenarios
String t = System.Text.Encoding.UTF8.GetString(bytes);
webBrsr.DocumentText = t;