Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decode escaped Url without using HttpUtility.UrlDecode

Tags:

.net

url

Is there any function that converts an escaped Url string to its unescaped form? System.Web.HttpUtility.UrlDecode() can do that job but I don't want to add a reference to System.Web.dll. Since my app is not a web application, I don't want to add a dependency for only using a function in an assembly.

UPDATE: Check Rick Strahl's blog post about the same issue.

like image 620
huseyint Avatar asked Oct 27 '08 11:10

huseyint


People also ask

What does Httputility Urldecode do?

WebUtility.UrlDecode(String) Method (System.Net)Converts a string that has been encoded for transmission in a URL into a decoded string.

How do you decode a space in a URL?

URL encoding replaces unsafe ASCII characters with a "%" followed by two hexadecimal digits. URLs cannot contain spaces. URL encoding normally replaces a space with a plus (+) sign or with %20.

Does browser automatically decode URL?

It is a usual task in web development, and this is generally done while making a GET request to the API with the query params. The query params must also be encoded in the URL string, where the server will decode this. Many browsers automatically encode and decode the URL and the response string.


1 Answers

EDIT: Use the static method Uri.UnescapeDataString() to decode your URLs:

Encoded: http%3a%2f%2fwww.google.com%2fsearch%3fhl%3den%26q%3dsomething%20%2323%26btnG%3dGoogle%2bSearch%26aq%3df%26oq%3d

Decoded: http://www.google.com/search?hl=en&q=something #23&btnG=Google+Search&aq=f&oq=

like image 178
Igal Tabachnik Avatar answered Sep 24 '22 09:09

Igal Tabachnik