Lamis
Lamis

Reputation: 466

URL Decode in java is not giving the same result to URL Decode php

I have made simple encryption/decryption method in php that I'm trying to move to Java

In my code, I get the value from url and urldecode it before passing it to my decryption function

This is giving right results in php but not in java

here is my test sample in php

urldecode("%9A%DC%CD%E1%DA%E2%D4%EA%C4%E6%9C%DA%D5%AD%CD%DF%E3%E4%C6%DB%A3%95%C4%DC%D2")

here is what I'm trying to do in JAVA

java.net.URLDecoder.decode("%9A%DC%CD%E1%DA%E2%D4%EA%C4%E6%9C%DA%D5%AD%CD%DF%E3%E4%C6%DB%A3%95%C4%DC%D2")

and the results I'm getting are totally different. anyone can lead me to where I messed up?

thanks


Upvotes: 1

Views: 1504

Answers (2)

Ankit Jajoo
Ankit Jajoo

Reputation: 910

When your are using only

decode(String s)

which is deprecated, the resulting string may vary depending on the platform's default encoding. Instead, use the

decode(String s,String enc)

method to specify the encoding. It decodes a application/x-www-form-urlencoded string using a specific encoding scheme.

enc can be "UTF-8", "ISO 8859-1" etc....

Upvotes: 1

Francisco Spaeth
Francisco Spaeth

Reputation: 23903

Consider trying instead:

java.net.URLDecoder.decode("%9A%DC%CD%E1%DA%E2%D4%EA%C4%E6%9C%DA%D5%AD%CD%DF%E3%E4%C6%DB%A3%95%C4%DC%D2", "UTF-8")

in JAVA java.net.URLDecoder.decode(String) is deprecated.

Upvotes: 2

Related Questions