First, the protocol specification, RFC 1738, defines that the URL address cannot contain characters other than: 0-9, A-Za-Z,-, that is, the URL contains special characters, for example, $ -_. +! * '(), All must be encoded.
There are several reasons for such definition:
1. Many special characters in HTML code, such as '#', are used to locate HTML (Anchor). Therefore, such characters have special meanings, it cannot be directly used for sending and must be encoded.
2. if it contains some non-printable control characters, it cannot be printed and displayed normally. Therefore, it must be encoded before transmission. Functions/control characters in the ASCII character set.
3. Some Reserved characters (&, =,:) and unsafe characters (<, >,#) are also required. Therefore, the URL address must be encoded.
4. There are also some easy-to-think characters, such as spaces. If they appear in the URL address, it is difficult to determine whether the content before and after the space belongs to the URL. Therefore, for special characters such as spaces, it must be encoded.
Why is the URL not sent directly but encoded before being sent?