无法在System.windows.Forms.WebBrowser中打印英语以外的语言

时间:2011-08-30 11:57:25

标签: c# encoding browser

我正在尝试使用System.windows.Forms.WebBrowser以外的语言显示内容,但结果编码不正确。我该怎么做才能显示俄罗斯?

我正在下载并显示如下字符串:

 System.Net.WebClient wc = new System.Net.WebClient();
 webBrsr.DocumentText = wc.DownloadString(url);

1 个答案:

答案 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;