Why browsers encode url in this form ?
From:
http://www.开发者_如何学JAVAexample.com
to:
http%3A%2F%2Fwww.example.com
URLs can only be sent over the Internet using the ASCII character-set.
Since URLs often contains characters outside the ASCII set, the URL has to be converted. URL encoding converts the URL into a valid ASCII format.
URL encoding replaces unsafe ASCII characters with "%" followed by two hexadecimal digits corresponding to the character values in the ISO-8859-1 character-set.
URLs cannot contain spaces. URL encoding normally replaces a space with a + sign.
You can read more here:
INTRODUCTION TO URL ENCODING / URL ENCODED STRINGS
Because URI's can only contain ASCII characters, so other character have to be encoded with % plus two hexadecimal digits. % itself for instance would be encoded (escaped if you like) as %25, because hexadecimal 25, or decimal 37 is the codepoint for %.
That encoding is not necessary though, as : and / are allowed in the bare form. The point is that the standard does define it to be exactly equivalent to using / or : directly. But many browsers and servers do in fact not observe this for such common characters.
Another thing is using URI's as namespace identifiers, such as XML does. Where even though two strings may correspond to the same URI, they can in fact be different namespaces because the character string is different.
Because ":" and "/" have a designated meaning in URLs. ":" separates the scheme from the scheme specific part. "/" is used to separate parts of the path from each other. Two "/" at the beginning of the scheme specific part in HTTP URLs designate the URL as an absolute URL. If you do not want those characters to have that meaning (like when they are part of the query string), you have to encode them.
精彩评论