问题
I have read the question Why do you need to encode URLs
but I still confused:
- Why the W3C just allow more character could exist in URL?So it could avoid encoding?
- Why there is exist decode
回答1:
The URL representation of characters may differ from the characters you have in your code. In other words, there is a specific grammar that defines how URLs are assembled. Special characters that are used in forming a URL need to be encoded so that they do not cause unexpected results.
Now to answer your questions more specifically:
They may already allow some of the characters you are thinking of, but these characters (&, ?, for example) are given special meaning to function in a certain way. Therefore, they cannot be used in a different context. From the link to the question you posted, it also looks like in the example of the space character, it is not supported because of the problems it would introduce in its use.
Decode is useful for decoding the URL to get the string representation of the URL before it was encoded for manipulation/other functions in the application.
来源:https://stackoverflow.com/questions/17267059/why-need-encode-and-decode-urls