URL 中的空格? [英] Spaces in URLs?
问题描述
w3fools 声称 URL 可以包含空格:http://w3fools.com/#html_urlencode
w3fools claims that URLs can contain spaces: http://w3fools.com/#html_urlencode
这是真的吗?URL 如何包含未编码的空格?
Is this true? How can a URL contain an un-encoded space?
我的印象是 HTTP 请求的请求行 使用了空格作为分隔符,格式为 {the method}{space}{the path}{space}{the protocol}
:
I'm under the impression the request line of an HTTP Request uses a space as a delimiter, being formatted as {the method}{space}{the path}{space}{the protocol}
:
GET /index.html http/1.1
那么 URL 怎么可以包含空格呢?如果可以,用+
代替空格的做法从何而来?
Therefore how can a URL contain a space? If it can, where did the practice of replacing spaces with +
come from?
推荐答案
URL 不得包含文字空格.它必须使用 百分比编码 或不同的编码进行编码使用网址安全字符(例如application/x-www-form-urlencoded 使用 +
而不是 %20
作为空格).
A URL must not contain a literal space. It must either be encoded using the percent-encoding or a different encoding that uses URL-safe characters (like application/x-www-form-urlencoded that uses +
instead of %20
for spaces).
但是这句话是对是错取决于解释:从语法上讲,URI 不能包含文字空间,并且必须进行编码;从语义上讲,%20
不是空格(显然)但它代表一个空格.
But whether the statement is right or wrong depends on the interpretation: Syntactically, a URI must not contain a literal space and it must be encoded; semantically, a %20
is not a space (obviously) but it represents a space.
这篇关于URL 中的空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!