3

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!

2 Answers 2

6

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.

Sign up to request clarification or add additional context in comments.

Comments

3

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

П
р
и
в
е
т

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.