HTTP路径必须以斜杠开头吗? [英] Do HTTP paths have to start with a slash?
问题描述
我对HTTP格式有疑问。 HTTP请求的第一行如下所示:
GET /path/to/resource.txt HTTP / 1.1
或换句话说:
METHOD URI HTTP-VERSION
是否需要 URI
以 /
字符开头,以便 /path/to/resource.txt
与路径/到/ resource.txt
相同,两者都有效吗?
如果是领先 /
不是必需的,是 GET / HTTP / 1.1
和 GET HTTP / 1.1
也一样吗? ( GET
和 HTTP / 1.1
之间的两个空格)
请参阅 RFC 7230,第5.3节请求目标:
获得入站连接后,客户端发送带有请求的HTTP
请求消息(第3节) -target派生自
目标URI。请求目标有四种不同的格式,
取决于所请求的方法和请求
是否代理。request-target = origin-form
/ absolute-form
/ authority-form
/ asterisk-form
你在谈论原型,在 5.3.1小节:
当直接向源服务器发出请求时,除了
CONNECT或服务器范围的OPTIONS请求(如下所述),客户端
必须只发送目标$ b的绝对路径和查询组件$ b URI作为请求目标。 如果目标URI的路径组件为
为空,则客户端必须发送/作为
request-target的原始格式内的路径。主机头字段也是发送,如
第5.4节中所定义。
例如,希望检索标识为
的
资源的表示的客户
http://www.example.org/where?q=now
$ p直接来自原始服务器的$ p>
将打开(或重复使用)与主机www.example.org的端口80的TCP
连接并发送
行:GET / where?q = now HTTP / 1.1
主持人:www.example.org
早期在第2.7节为
absolute-path = 1 *(/segment)
所以是的,需要一些目标标识符,路径始终以斜杠为前缀,如果未知,空或不适用,则为 /
。
I have a question regarding the HTTP format. The first line of a HTTP request looks something like this:
GET /path/to/resource.txt HTTP/1.1
or in other words:
METHOD URI HTTP-VERSION
Is it required that the URI
starts with the /
character so that /path/to/resource.txt
would be the same as path/to/resource.txt
and both are valid?
And if a leading /
is not required, are GET / HTTP/1.1
and GET HTTP/1.1
the same too? (two spaces between GET
and HTTP/1.1
)
See RFC 7230, section 5.3 Request target:
Once an inbound connection is obtained, the client sends an HTTP request message (Section 3) with a request-target derived from the target URI. There are four distinct formats for the request-target, depending on both the method being requested and whether the request is to a proxy.
request-target = origin-form / absolute-form / authority-form / asterisk-form
You're talking about origin-form, described in subsection 5.3.1:
When making a request directly to an origin server, other than a CONNECT or server-wide OPTIONS request (as detailed below), a client MUST send only the absolute path and query components of the target URI as the request-target. If the target URI's path component is empty, the client MUST send "/" as the path within the origin-form of request-target. A Host header field is also sent, as defined in Section 5.4.
For example, a client wishing to retrieve a representation of the resource identified as
http://www.example.org/where?q=now
directly from the origin server would open (or reuse) a TCP connection to port 80 of the host "www.example.org" and send the lines:
GET /where?q=now HTTP/1.1 Host: www.example.org
And an "absolute path" is defined earlier in section 2.7 as
absolute-path = 1*( "/" segment )
So yes, some target identifier is required, the path is always prefixed with a slash, and if unknown, empty or inapplicable, it is /
.
这篇关于HTTP路径必须以斜杠开头吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!