Java 两个 URL 编码字符串之间的差异

发布于 2024-11-06 10:01:15 字数 529 浏览 1 评论 0原文

下面两个编码字符串有什么区别?

%D0%9E%D0%BA%D0%B6%D1%8D%D0%B7

%26%231055%3B%26%231088%3B%26%231080%3B%26%231074%3B%26%231077%3B%26%231090%3B

正在尝试将俄语文本“Привет”进行 URL 编码到上面的第二个编码字符串中(W3Schools 编码器 正确执行),但我使用的 URL 编码器不断为我提供上面的第一个编码字符串。我正在使用 W3 联盟的 URLUTF8Encoder.java 。我必须使用这个,因为我正在开发一个需要 J2ME 的移动平台。

谢谢!

What is the difference between the following two encoded strings?

%D0%9E%D0%BA%D0%B6%D1%8D%D0%B7

and

%26%231055%3B%26%231088%3B%26%231080%3B%26%231074%3B%26%231077%3B%26%231090%3B

I am trying to URL Encode the russian text "Привет" into the second encoded string above (the W3Schools encoder does it correctly), but the URL encoder that I am using keeps giving me the first encoded string above. I am using URLUTF8Encoder.java from the W3 consortium. I have to use this one as I am working on a mobile platform requiring J2ME.

Thanks!

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

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

发布评论

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

评论(2

情绪失控 2024-11-13 10:01:15

w3schools 的 URL 编码器做得完全错误。 %D0%9E%D0%BA%D0%B6%D1%8D%D0%B7 完全有效。这也是我做的时候得到的

String encoded = URLEncoder.encode("Привет", "UTF-8");

当我按如下方式对 w3schools 的答案进行 URL 解码

String decoded = URLDecoder.decode("%26%231055%3B%26%231088%3B%26%231080%3B%26%231074%3B%26%231077%3B%26%231090%3B", "UTF-8");

时,我得到 Приве т 正是这些俄语字符,但随后转换为 XML 实体 首先。

顺便说一下,w3schools 网站与 W3 Consortium 没有任何关系。另请参阅w3fools

The URL encoder at w3schools is doing it utterly wrong. The %D0%9E%D0%BA%D0%B6%D1%8D%D0%B7 is perfectly valid. That's also what I get when I do

String encoded = URLEncoder.encode("Привет", "UTF-8");

When I URL-decode the w3schools' answer as follows

String decoded = URLDecoder.decode("%26%231055%3B%26%231088%3B%26%231080%3B%26%231074%3B%26%231077%3B%26%231090%3B", "UTF-8");

then I get Привет which are exactly those Russian characters, but then converted into XML entities first.

That w3schools site is by the way in no way related to W3 Consortium. See also w3fools.

甲如呢乙后呢 2024-11-13 10:01:15

您的字符串“Привет”编码为:

%D0%9E    
%D0%BA
%D0%B6
%D1%8D
%D0%B7

第二个字符串似乎在网址编码之前转换为 HTML 实体:

%26%231055%3B
%26%231088%3B
%26%231080%3B
%26%231074%3B
%26%231077%3B
%26%231090%3B

%26 is &, %23< /code> 为 #%3B;

П
р
и
в
е
т

Your string "Привет" is encoded as:

%D0%9E    
%D0%BA
%D0%B6
%D1%8D
%D0%B7

The second string seems to be converted into HTML entities before url-encoding:

%26%231055%3B
%26%231088%3B
%26%231080%3B
%26%231074%3B
%26%231077%3B
%26%231090%3B

%26 is &, %23 is #, %3B is ;:

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