I have a parameter which I must pass as part of a url. The parameter contains this character: ß
When I encode this string, I am expecting this: %DF
but instead i’m getting: %c3%9f
Here is a line of C# which I have been using to test
string test = HttpUtility.UrlEncode("ß");
This is because the default implementation of UrlEncode is based on the UTF8 character encoding. Actually this is entirely within your control.
For example, the following code:
Outputs the following:
Of course the danger with using another encoding on a URI is that some characters can not be represented at all…
for example, this code:
Will output the following:
You can see in the later example the encoding is “%3f” which, when unencoded is equal to a question mark “?”, not the input character of 312 (0x138).
In a nutshell there is nothing wrong with encoding “ß” as “%c3%9f”, to the contrary, it is the correct representation. Yet if you must have the encoding “%DF for the remote server to correctly decode it, then use the 1252 codepage as shown.