Windows Phone 7 中具有特定编码的 UrlEncode?

发布于 2024-12-20 13:03:20 字数 588 浏览 4 评论 0原文

在“常规”.NET 中,有一个 UrlEncode 方法,它采用 Encoding范围。 有没有这样的 WP7.NET 中的 UrlEncode 方法?

我位于瑞典,我正在尝试从 REST 服务检索数据,该服务期望请求中包含 ISO-8859-1(但以 UTF-8 进行响应)。 当进行搜索(input=frölunda)并仅使用 UrlEncode 时,我得到 input=fr%C3%B6lunda,由于“丢失”ö,它返回非常奇怪的结果。 使用带有 iso-8859-1 编码的 .NET UrlDecode 我得到 input=fr%F6lunda ,它返回预期的结果。

我必须实现自己的 UrlEncode 吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

A君 2024-12-27 13:03:21

有趣的是,微软似乎正在通过 Silverlight 遵循这一标准。 维基百科 说:

[...] 应根据 UTF-8 将所有其他字符转换为字节,并且
然后对这些值进行百分比编码。这一要求是在
2005 年 1 月,RFC 3986 发布。引入 URI 方案
在此日期之前不受影响。

所以看起来他们放弃了编码的选择,因为无论如何只允许一种。

除此之外,您并不是唯一遇到此问题的人。建议是:不要重新发明轮子,使用已经编写的代码来获取您需要的 HtmlEncode。 (除了建议使用 Uri.EscapeUriString 而不是客户端的 HttpUtility.UrlEncode - 但我无法判断。)

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.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文