Reputation: 77
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?
Upvotes: 2
Views: 2181
Reputation: 941565
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"
Upvotes: 4