url - 为什么 '%20' 在 URL 中用作空格的起源

标签 url encoding

我很想知道为什么 '%20' 被用作 URL 中的空格,特别是为什么使用 %20 以及为什么我们甚至首先需要它。

最佳答案

它叫做 percent encoding .某些字符不能在 URI 中(例如 # ,因为它表示 URL 片段),因此它们用可以是的字符表示( # 变成 %23 )

这是同一篇文章的摘录:

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 :
> ' '.charCodeAt(0)
32

这是20在 base-16 中:
> ' '.charCodeAt(0).toString(16)
"20"

在它前面加上一个百分号,你会得到 %20 .

关于url - 为什么 '%20' 在 URL 中用作空格的起源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13900835/

相关文章:

encoding - 这是什么类型的编码?我听说它是​​ Bencode,但它看起来并不标准

c# - HttpResponse 中的 StatusDescription 编码

php - 整个网站显示为怪异字符

wordpress - 无法使用以问号开头的网址抛出 404 错误

javascript - 如何将 .jpeg url 中的图像访问到 Base64 编码的 javascript

php - 如何使用php从url读取xml文件

java - 如何实现xxx.domainname.com URL模式?

javascript - AngularJS 1.1.5 - 自动向 URL 添加散列标签

将 PDF 作为字符串转换为 NSData 后,iOS UIWebView 无法找到 PDF 标题

unicode - 了解 Unicode : Surrogate Blocks, 非字符