Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UrlEncode with specific Encoding in Windows Phone 7?

In "regular" .NET there is a UrlEncode method that takes an Encoding parameter. Is there no such UrlEncode method in .NET for WP7?

I'm located in Sweden and I'm trying to retrieve data from a REST service that expects ISO-8859-1 in the requests (but responds in UTF-8). When doing a search (input=frölunda) and just using UrlEncode i get input=fr%C3%B6lunda which returns very strange results because of the "missing" ö. Using the .NET UrlDecode with iso-8859-1 encoding i get input=fr%F6lunda which returns the excpected results.

Do I have to implement my own UrlEncode?

like image 742
jovnas Avatar asked Nov 04 '22 09:11

jovnas


1 Answers

Interesting, it seems like Microsoft is following the standard here with Silverlight. Wikipedia says:

[...] should convert all other characters to bytes according to UTF-8, and then percent-encode those values. This requirement was introduced in January 2005 with the publication of RFC 3986. URI schemes introduced before this date are not affected.

So it seems like they dropped the choice of encoding since only one is allowed anyway.

Apart from that you are not the only one having this problem. The recommendation there is: don't reinvent the wheel and use code already written to get the HtmlEncode you need. (Apart from the recommendation to use Uri.EscapeUriString instead of HttpUtility.UrlEncode on the client side - but I can't judge that.)

like image 89
Heinrich Ulbricht Avatar answered Nov 15 '22 00:11

Heinrich Ulbricht