URL encoding (URL encoding), also known as percent-encoding (percent-encoding), refers to the Uniform Resource Locator (URL) encoding mechanism for a specific context
UrlEncode: Encodes a string as a URL
return value: String
Function type: Encoding processing
Coding principle:
Convert the required characters into 16, then from right to left, take 4 bits (less than 4 direct processing), each 2 bits to do a bit, preceded by%, encoded into%XY format.
The essence of URL encode is the correct use of percent encode (percent-semicolon encoding)
For example: The ASCII code is-10544, the corresponding 16 binary is ffffffffffffd6d0, then the UrlEncode encoding result is:%d6%d0
Current Coding principle:
At the beginning of the WWW, the practice is to convert the character stream into byte streams, in accordance with the ASCII characters corresponding to bytes one by one can be converted to each other, using the corresponding ASCII character integer value as a% of the latter two 16 characters, constitute percent encoding. A number of percent encoding generation methods have emerged, resulting in the difficulty of identifying URIs.
The current practice, the designation or system default to use UTF8 into a stream of bytes, each byte into a percent encoding, for example: Chinese "netease" URL Code of%e7%bd%91%e6%98%93, and its UTF8 byte stream E7 bd e6 93, you can see its one by one correspondence
principles:In the constituent characters of the URI, the safest scheme is to use the set of "reserved character" and "non-reserved character" correctly.
Reserved characters: Characters that function in the URL, such as &,?. So the URL rules are "reserved".
reserved Words (Reserved):! * ‘ () ; : @ & = + $,/? # []
non-reserved Words (unreserved): 0 to 9 of the number-_. ~ A to Z A to Z
Follow the principles:
1 Do not unreserved (non-reserved words) do percent encode (percent code)
2 all characters except reserved and non-reserved words must be percent encode (percent-semicolon encoded)
3 when the reserved character is not used for the URL delimiter, but for other locations, such as the value after query, to do the reserved word used to do percent encode (percent code)
URL encoding (URL encoding)