url cyrillic encoding issue (with webbrowser control)

南笙酒味 提交于 2019-12-11 02:50:57

问题


I use C# web browser to send request. But url includes cyrillics symbols, and I use proxy so I need to encode the url.

The origin url: http://mysite.com/info?q=москва+дизайн

I need http://mysite.com/info?q=%E4%E8%E7%E0%E9%ED+%EC%EE%F1%EA%E2%E0

What C# functions exist to make that?


回答1:


You can use System.Web.HttpUtility.UrlEncode(). Its default encoding is utf-8, yours look like Windows code page 1251 with the words reversed. I suppose you ought to pass Encoding.Default. The closest match is:

var enc = Encoding.GetEncoding(1251);
var url = "http://mysite.com/info?q=" + 
          System.Web.HttpUtility.UrlEncode("москва+дизайн", enc);

Which produces:

"http://mysite.com/info?q=%ec%ee%f1%ea%e2%e0%2b%e4%e8%e7%e0%e9%ed"


来源:https://stackoverflow.com/questions/19196258/url-cyrillic-encoding-issue-with-webbrowser-control

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!