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
  • 51,962
  • 152
  • 427
  • 752

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
  • 74,049
  • 16
  • 131
  • 175
8

%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
  • 442,112
  • 142
  • 972
  • 1,088
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
  • 45,515
  • 15
  • 108
  • 150
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,389
  • 28
  • 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
  • 17,186
  • 14
  • 73
  • 95