开发者

Java difference between two URL Encoded strings

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!


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.


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 ;:

П
р
и
в
е
т
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜