Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UriBuilder fail to encode UriBuilder registered sign

I am working on an asp.net mvc web application. now i have a value for operating system which equal to :-

enter image description here

and i am using the following code to build a url containing the above value as follow:-

var query = HttpUtility.ParseQueryString(string.Empty);
query["osName"] = OperatingSystem;


var url = new UriBuilder(apiurl);
url.Query = query.ToString();
string xml = client.DownloadString(url.ToString());

but the generated url will contain the following value for the operating system :-

osName=Microsoft%u00ae+Windows+Server%u00ae+2008+Standard

so the UriBuilder will encode the registered sign as %u00ae+ which is wrong since when i try to decode the %u00ae+ using online site such as http://meyerweb.com/eric/tools/dencoder/ it will not decode %u00ae+ as register sign ??? so can anyone adivce on this please, how i can send the registered sign inside my url ? is this a problem within UrilBuilder ?

Thanks

EDIT This will clearly state my problem.. now i pass the asset name valueas £ ££££££ now the query["assetName"] will get the correct value.. but inside the query the value will get encoded wrongly (will not be encoded using UTF8 )!!!

enter image description here

like image 584
john Gu Avatar asked Jul 27 '16 00:07

john Gu


1 Answers

Try this:

url.Query = Uri.EscapeUriString(HttpUtility.UrlDecode(query.ToString()));

As mentioned here HttpUtility.ParseQueryString() always encodes special characters to unicode

like image 86
Sergey Lobanov Avatar answered Nov 01 '22 14:11

Sergey Lobanov