Search code examples
c#php.neturlencode

Error converting urlencode from PHP to C#


I have a class in PHP that encodes this code "?�m�U", using urlencode(), resulting in "%3F%B6%16m%BEU". However, when I try to encode with c# uisng HttpUtility.UrlEncode(), the result is not the same. The method in c# has a second parameter "Encoding.SOMETHING". I've tried each one of the possible paramaters, but it still doesn't work.

Does anyone know how I can fix this?


Solution

  • This one should work:

    string utf8Encoded = System.Web.HttpUtility.UrlEncode(YOURURL, Encoding.UTF8);