When using HttpUtility from System.Web, I find that everytime I call the method .ParseQueryString I am having special characters encode to their unicode equivalent represent
The problem is in:
urlBuilder.Query = query.ToString();
HttpUtility.ParseQueryString
returns a NameValueCollection
but is actually an internal class called HttpValueCollection
. This class has an override of the ToString()
method. It generates an encoded query string but for its URL encoding it uses HttpUtility.UrlEncodeUnicode
(tinyurl.com/HttpValue). This results in the %uXXXX values.
If you need a different type of URL encoding you might want to avoid HttpUtility.ParseQueryString
or decode the result of ToString()
and encode it afterwards:
urlBuilder.Query = Uri.EscapeUriString(HttpUtility.UrlDecode(query.ToString()));