开发者

Unable to print languages other than English in System.windows.Forms.WebBrowser

开发者 https://www.devze.com 2023-03-31 13:38 出处:网络
I am trying to use System.windows.Forms.WebBrowser to display a content in the languages other than English, but the resulting encoding is incorrect. What should I do to display for exa开发者_StackOve

I am trying to use System.windows.Forms.WebBrowser to display a content in the languages other than English, but the resulting encoding is incorrect. What should I do to display for exa开发者_StackOverflow中文版mple Russian?

I am downloading and displaying a string as following:

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


The problem is with the WebClient and how it is interpreting the string encoding. One solution is to download the data as raw bytes and parse it out manually:

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;
0

精彩评论

暂无评论...
验证码 换一张
取 消