Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 443
littleK Avatar asked Apr 25 '26 19:04

littleK


2 Answers

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.

like image 90
BalusC Avatar answered Apr 27 '26 11:04

BalusC


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

П
р
и
в
е
т
like image 36
Anders Lindahl Avatar answered Apr 27 '26 12:04

Anders Lindahl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!