c# - URL encode ASCII/UTF16 characters -


I am trying to url - to encode some stars, though, to the methods provided by the net framework There are problems with

For example, I am trying to encode strings that contain 'one' character. For example, I hope this character should be '% E2' (and encoded as a PHP system, I hope it also) ....

I tried to use these methods:

  system Web. HTTTY Urlcode ("one"); System.Web.HttpUtility.UrlPathEncode ('A'); Uri.EscapeUriString ('A'); Uri.EscapeDataString ('A');  

However, they all encode this character:% C3% A2

I think there is something like this in the net with the fact that . Net is UTF-16 encoding. Therefore, to avoid this problem, I can write it for example:

  "%" + ((int) character). Ostring ("x")  

However, I would like to know whether the structure already has an underlying method (I can not get the answer here or anywhere because my character is encoded in this way)?

The reason is not is that the .NET UTF-16 encoded string Uses. The reason for this is that by default UTF-8 uses, and % C3% A2 correct code :

>> 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 UTF 8 as the second parameter.

If you prefer a different encoding (for example, or codepap 1252, where matches with % E2 ) ), You can use another surcharge which allows you to specify the encoding:

  var x = HttpUtility.UrlEncode ("A", encoding. GetEncoding (1252));  

Comments