What is url encoding &?

2019-06-15 07:24发布

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.

5条回答
放我归山
2楼-- · 2019-06-15 07:26

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

查看更多
戒情不戒烟
3楼-- · 2019-06-15 07:33

%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.

查看更多
祖国的老花朵
4楼-- · 2019-06-15 07:34

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.

查看更多
疯言疯语
5楼-- · 2019-06-15 07:44

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.

查看更多
Luminary・发光体
6楼-- · 2019-06-15 07:49

& 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>
查看更多
登录 后发表回答