url encoding
URL encoding is an encoding format used in URLs.
The standard allows the use of arbitrary data inside a Uniform Resource Identifier (a URI; typically a URL) while using only a narrow set of US-ASCII characters.
The encoding exists because URLs and HTTP request parameters often contain characters (or other data) that cannot be represented with the limited set of US-ASCII characters (i.e. control characters, etc.).
arbitrary随心所欲的
not seeming to be based on a reason, system or plan and sometimes seeming unfair
Reserved and unreserved characters
Unreserved characters are characters that have no special meaning; they can be displayed as-is and require no special handling. These include uppercase and lowercase letters (A-Z, a-z), decimal digits (0-9), hyphen (-), period (.), underscore (_), and tilde (~).
Reserved characters, on the other hand, are characters that may delimit the URI into sub-components: characters such as / # & and others. The following is the list of all reserved characters: ! # $ & ‘ ( ) * + , / : ; = ? @ [ ].
We cannot use reserved character as-is, because this would create ambiguous URIs.
Percent encoding
To encode reserved characters, we use the percent-encoding scheme. In percent-encoding, each byte is encoded as a character triplet that consists of the percent character % followed by the two hexadecimal digits that represent the byte numeric value.
For instance, %23 is the percent-encoding for the binary octet 00100011, which in US-ASCII, corresponds to the character #.
Other characters
Percent encoding is also used to represent other characters; characters that are neither reserved nor unreserved.
As an example, imagine a GET request containing a non-ASCII string parameter, such as a search query zajec in jež which is Slovenian for a rabbit and a hedgehog.
In such cases, we have to first encode non-ASCII characters as UTF-8 and then encode each byte of the new string with percent-encoding.
Encoding the space character
using the +
instead of %20
is valid only when encoding the application/x-www-form-urlencoded content, such as the query part of an URL.