@ being converted into string when passing in the URL

435 views Asked by At

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/[email protected]');

Please take a look at the given fiddle:

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

How can I avoid this issue?

3

There are 3 answers

2
Samir Selia On BEST ANSWER

Your URL https://secure.rspcdn.com/xprr/red/PID/3428/SID/[email protected] 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

2
m0sa On

Use encodeURIComponent for the email address parameter:

window.open('https://secure.rspcdn.com/xprr/red/PID/3428/SID/rentown?email=' + encodeURIComponent('[email protected]'))

The correct value for the email parameter (returned by encodeURIComponent) is ˙amrinder%40odz.com˙, which will be interpreted as [email protected] 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.

0
TIGER On

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('[email protected]'))

Note :

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