gpt4 book ai didi

file - HTTP 路径必须以斜杠开头吗?

转载 作者:可可西里 更新时间:2023-11-01 15:27:03 25 4
gpt4 key购买 nike

我有一个关于 HTTP 格式的问题。 HTTP 请求的第一行看起来像这样:

GET /path/to/resource.txt HTTP/1.1

或者换句话说:

METHOD URI HTTP-VERSION

是否要求 URI/ 字符开头,以便 /path/to/resource.txtpath/to/resource.txt 两者都有效吗?

如果不需要前导 /GET/HTTP/1.1GET HTTP/1.1 也一样吗? (GETHTTP/1.1 之间的两个空格)

最佳答案

参见 RFC 7230, section 5.3 Request target :

Once an inbound connection is obtained, the client sends an HTTPrequest message (Section 3) with a request-target derived from thetarget URI. There are four distinct formats for the request-target,depending on both the method being requested and whether the requestis to a proxy.

request-target = origin-form
                / absolute-form
/ authority-form
/ asterisk-form

你说的是原始形式,在 subsection 5.3.1 中有描述。 :

When making a request directly to an origin server, other than aCONNECT or server-wide OPTIONS request (as detailed below), a clientMUST send only the absolute path and query components of the targetURI as the request-target. If the target URI's path component isempty, the client MUST send "/" as the path within the origin-form ofrequest-target. A Host header field is also sent, as defined inSection 5.4.

For example, a client wishing to retrieve a representation of theresource identified as

http://www.example.org/where?q=now

directly from the origin server would open (or reuse) a TCPconnection to port 80 of the host "www.example.org" and send thelines:

GET /where?q=now HTTP/1.1
 Host: www.example.org

并且“绝对路径”在section 2.7 中定义得较早作为

 absolute-path = 1*( "/" segment )

所以是的,一些目标标识符是必需的,路径总是以斜杠为前缀,如果未知、为空或不适用,则为 /

关于file - HTTP 路径必须以斜杠开头吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27638278/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com