0

I have a certain text I am encoding in JS using encodeURIComponent. The original text is

weoowuyteeeee !_.

Test could you please resubmit again? 

I am doing the following in my JS code before sending it.

var text = encodeURIComponent($("#txt11").val());

Should I not be doing that?

Once I encode it using encodeURIComponent, it becomes


weoowuyteeeee%2520!_.%252C%250A%250ATest%252C%2520%2520could%2520you%2520please%2520resubmit%2520again%253F


I'm trying to decrypt the same on the Java side using

String decodedString1 = URLDecoder.decode(myObject.getText(), "UTF-8");

but I see this as the output, not the original text. What am I doing wrong?


weoowuyteeeee%20!_.%2C%0A%0ATest%2C%20%20could%20you%20please%20resubmit%20again%3F


p0tta
  • 1,461
  • 6
  • 28
  • 49

1 Answers1

3

You are encoding your data twice.

Initially, you have encoded your data and later it is encoded again.

Eg: Let your text be

Hello World

After encoding it becomes

Hello%20World

If you encode again it becomes

Hello%2520World

Reason

% from %20 is encoded to %25. So the space becomes %2520.

Normal AJAX can will automatically encode your data before sending to the server side. Check where the 2nd encoding is happening.

Stenal P Jolly
  • 737
  • 9
  • 20