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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With