为什么'%20'用作URL中的空格的原点 [英] The origin on why '%20' is used as a space in URLs
问题描述
我有兴趣知道为什么'%20'用作URL中的空格,特别是为什么使用%20,为什么我们甚至首先需要它。
I am interested in knowing why '%20' is used as a space in URLs, particularly why %20 was used and why we even need it in the first place.
推荐答案
这是编码百分比。某些字符不能在URI中(例如#
,因为它表示URL片段),所以它们用可以是(#
成为%23
)
It's called percent encoding. Some characters can't be in a URI (for example #
, as it denotes the URL fragment), so they are represented with characters that can be (#
becomes %23
)
这是同一篇文章的摘录: / p>
Here's an excerpt from that same article:
当保留的一个字符(保留字符)具有
特殊含义(保留目的)时某个上下文和一个URI
scheme表示有必要将该字符用于其他
目的,那么该字符必须是的百分号编码。
编码保留字符的百分比编码涉及将
字符转换为ASCII对应的字节值,然后将
表示为一对十六进制数字。 ,
前面带有百分号(%),用作转义字符,然后在URI中使用
代替保留字符。 (对于
非ASCII字符,通常将其转换为
UTF-8中的字节序列,然后每个字节值如上所示。)
When a character from the reserved set (a "reserved character") has special meaning (a "reserved purpose") in a certain context, and a URI scheme says that it is necessary to use that character for some other purpose, then the character must be percent-encoded. Percent-encoding a reserved character involves converting the character to its corresponding byte value in ASCII and then representing that value as a pair of hexadecimal digits. The digits, preceded by a percent sign ("%") which is used as an escape character, are then used in the URI in place of the reserved character. (For a non-ASCII character, it is typically converted to its byte sequence in UTF-8, and then each byte value is represented as above.)
空格字符的字符代码是 32
:
The space character's character code is 32
:
> ' '.charCodeAt(0)
32
哪个是 20基础16中的
> ' '.charCodeAt(0).toString(16)
"20"
百分号在前面标记,你得到%20
。
Tack a percent sign in front of it and you get %20
.
这篇关于为什么'%20'用作URL中的空格的原点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!