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 representations. I have tried with many different encoding types, and all seem to produce the same result. An example of my code is here:
string text = "ich m?chte diese Bild für andere freigeben"
var urlBuilder = new UriBuilder(url);
var query = HttpUtility.ParseQueryString(urlBuilder.Query, Encoding.UTF8);
query["text"] = text;
urlBuilder.Query = query.ToString();
string finalUrl = urlBuilder.ToString();
And the string in finalUrl
that I would recieve from this would be:
text=ich+m%u00f6chte+diese+Bild+f%u00fcr+andere+freigeben
I have tried using Encoding.UTF8
,Encoding.ASCII
and Encoding.Default
and they all produce the same result. What can I do to reach my desired format of UrlEncoding:
text=ich%20m%C3%B6chte%20diese%20Bild%20f%C3%BCr%20andere%20freigeben
As always, Thanks in advance for the help/advice!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…