0

I am trying to post data to a URL through HTTP request, when I try to pass email then it converts @ into %252540.

Here is the URL:

window.open('https://secure.rspcdn.com/xprr/red/PID/3428/SID/rentown?email=amrinder@odz.com');

Please take a look at the given fiddle:

https://jsfiddle.net/amrindernoor/b8uvwr86/

How can I avoid this issue?

halfer
  • 19,824
  • 17
  • 99
  • 186
Amrinder Singh
  • 5,300
  • 12
  • 46
  • 88

3 Answers3

4

Your URL https://secure.rspcdn.com/xprr/red/PID/3428/SID/rentown?email=amrinder@odz.com has multiple internal redirects.

In each redirect, it encodes the already encoded email.

Here is the brief explanation on what exactly is causing the issue:

At first, @ is passed as it is.

During first redirection, it is encoded to %40 which is still valid.

Here after in each redirection, it gets encoded again resulting in %252540 as the final value.

Below is the screen shot that will give you a clear picture on this

enter image description here

Community
  • 1
  • 1
Samir Selia
  • 7,007
  • 2
  • 11
  • 30
  • ah! got it, but what's the solution now? as i don't have access of the server where the second redirection exists. – Amrinder Singh Dec 19 '16 at 10:17
  • There is no other solution other than contacting concerned person to grant you access so that encoding stuff can be fixed from root cause. – Samir Selia Dec 19 '16 at 11:26
0

Use encodeURIComponent for the email address parameter:

window.open('https://secure.rspcdn.com/xprr/red/PID/3428/SID/rentown?email=' + encodeURIComponent('amrinder@odz.com'))

The correct value for the email parameter (returned by encodeURIComponent) is ˙amrinder%40odz.com˙, which will be interpreted as amrinder@odz.com server-side.

After the change, that URL returns a 302 redirect to https://www.rsptrack.com/click.track?CID=287283&AFID=276422&SID=rentown&SID2=n&SID3=n&email=amrinder%40odz.com&zid=f197f1cfb16ae7d56748bca35ebe7658&tkp=3428&tku=4160&tks=86073803, which seems to contains the correct value for the email parameter.

m0sa
  • 10,712
  • 4
  • 44
  • 91
0

You can use encodeURIComponent() function to get it done. This function encodes special characters. In addition, it encodes the following characters: , / ? : @ & = + $ #

window.open('https://secure.rspcdn.com/xprr/red/PID/3428/SID/rentown?email=' + encodeURIComponent('amrinder@odz.com'))

Note :

Use the decodeURIComponent() function to decode an encoded URI component.

TIGER
  • 2,864
  • 5
  • 35
  • 45