16

Why is %2526 used instead of %26 to encode an &?

Im invoking a URL to an external site and when I encode the & as %2526 the parameters are passed correctly but when I just use %26 they are not.

blue-sky
  • 49,326
  • 140
  • 393
  • 691

5 Answers5

23

If you url-encode an ampersand you get %26. If you url-encode %26 you get %2526. Thus, it is url-encoded twice.

Sjoerd
  • 71,634
  • 16
  • 123
  • 171
7

%25 is the percent character, so %2526 URLDecoded results in

%26

which URLDecoded results in

&

For some reason, the call you make seems to require doubly percent encoded input. Without knowing more about what you're doing, it's impossible to know why, but I guess all is in order.

Pekka
  • 431,103
  • 135
  • 960
  • 1,075
1

Apparently it gets decoded twice in the process, first from %2526 to %26 and then from %26 to &.
You shouldn't dwell too long on the why; if this works, just use it like this.

Mr Lister
  • 44,061
  • 15
  • 107
  • 146
1

If the URL is used in return URL or value of another query string, the Reserved and Excluded characters should be doubled encoded. & is single-encoded as %26 and double-encoded as %2526.

Ebad Masood
  • 2,381
  • 27
  • 46
0

& is indeed encoded as %26.

You can test it creating an HTML file, opening it in a browser, inputing symbols you need to test and looking at the resulting URL in browser:

<form>
<input type='text' name='qwe'>
<input type='submit'>
</form>
Oleg Mikheev
  • 16,730
  • 13
  • 70
  • 94