Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Portable Class Library HttpUtility.UrlEncode

I understand that making web requests is quite well supported in the Portable Class Library. Is there any equivelant of HttpUtility.UrlEncode in the PCL? I need it for Windows Phone and Metro applications.

like image 425
Muhammad Rehan Saeed Avatar asked Jul 13 '12 14:07

Muhammad Rehan Saeed


People also ask

What does HttpUtility UrlEncode do?

HttpUtility.UrlEncode Method (System.Web)Encodes a URL string. These method overloads can be used to encode the entire URL, including query-string values. To encode or decode values outside of a web application, use the WebUtility class.

How do I use HttpUtility UrlEncode?

The HttpUtility. UrlEncode method uses UTF-8 encoding by default. Therefore, using the UrlEncode method provides the same results as using the UrlEncode method and specifying UTF8 as the second parameter. UrlEncode is a convenient way to access the UrlEncode method at run time from an ASP.NET application.


1 Answers

Use Uri.EscapeUriString and Uri.EscapeDataString

The only difference between the two is that EscapeDataString also encodes the RFC 2396 reserved characters which includes these characters ;/?:@&=+$,

It is important to note that neither of these methods encodes the RFC 2396 unreserved characters which includes -_.!~*'() So if you need these encoded then you will have to manually encode them.

like image 124
Jon Avatar answered Sep 19 '22 01:09

Jon