Search code examples
c#httpurlencodevbulletin

Url Encoding method for Special Character in c#


I use post method to submit data to and i have used

HttpUtility.UrlEncode(string data)

for Url Encode of data. But for some certain string the data at server side is shown different then what i submitted.

EX:

string data = "¦=¦=¦";
data = HttpUtility.UrlEncode(data);

after submitting data to server it shows string as ¦=¦=¦ but original string was ¦=¦=¦.

And which url encode i should use that can encode "(" to %28 , ")" to %29. I can find this.

I also used HttpUtility.UrlEncodeUnicode ,HttpUtility.UrlPathEncode but don't work. Which url encoding is suitable for this type of string?


Solution

  • In your code example you are using ASCII for char "¦" this is not a valid ASCII char. Use Unicode and it might work.

    System.Text.UnicodeEncoding uni = new UnicodeEncoding();
    byteArray = uni.GetBytes(data);