有效的 HTTP 标头? `GET /page.html Http1.0`?

发布于 2024-09-02 23:51:29 字数 624 浏览 2 评论 0 原文

好吧,我一直在阅读 HTTP 并找到此页面。这是一个发布在此处的 HTTP 请求示例:

GET /http.html Http1.1
Host: www.http.header.free.fr
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
Accept-Language: Fr
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 4.0)
Connection: Keep-Alive

我在 telnet 中尝试了它并且成功了。但在其他地方我都会看到这种请求行。

GET /http.html HTTP/1.1

重要的不同之处在于 HTTP 全部大写和 / 字符。

他们都正确吗?它们似乎都可以在我测试过的网站上运行。我浏览了 HTTP 的 RFC 但没有发现任何有用的东西。有其他人见过这种请求标头吗?官方支持吗?

Ok so I've been reading up on HTTP and found this page. This is an example HTTP request that was posted there:

GET /http.html Http1.1
Host: www.http.header.free.fr
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
Accept-Language: Fr
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 4.0)
Connection: Keep-Alive

I tried it in telnet and it worked. But everywhere else I see this kind of request line

GET /http.html HTTP/1.1

The important different is that HTTP is all caps and the / character.

Are they both correct? They both seem to work on the sites I've tested it on. I've skimmed the RFC of HTTP but didn't find anything of use. Has anyone else seen this kind of request header? Is it officially supported?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

清浅ˋ旧时光 2024-09-09 23:51:30

参考HTTP协议,必须是HTTP/1.1 HTTP/1.0 (较旧的)。现在就看http服务器是如何开发的了。它可能会接受它,但您不应该依赖它。

编辑:

HTTP 版本 = "HTTP" "/" 1*DIGIT
“。” 1*数字

现在协议是 1.1 所以你应该使用:GET /http.html HTTP/1.1

Refering to the HTTP protocol, it must be in HTTP/1.1 or HTTP/1.0 (older one). Now it depend how the http server was developed. It may accept it but you should not rely on it.

EDIT:

HTTP-Version = "HTTP" "/" 1*DIGIT
"." 1*DIGIT

And now the protocol is 1.1 so you should use: GET /http.html HTTP/1.1

霞映澄塘 2024-09-09 23:51:30

根据 RFC2145(第 3 页),

RFC791 [4] 在第 3.2 节中定义了“鲁棒性原则”:

<块引用>

实现的发送行为必须保守,而接收行为必须自由。

这个原则也适用于 HTTP。它是解释 HTTP 规范中可能仍然不明确的任何部分的基本基础。特别是,HTTP 的实现不应拒绝消息或生成不必要的错误。

特别是:

HTTP 规范的明确意图是,接收它不理解的消息标头的实现必须忽略该标头。

因此,如果版本号是“Http1.1”(无效),服务器会忽略版本号,并且可能会将消息解释为 HTTP/1.0 消息(甚至可能是 HTTP/0.9!)。当然,您不应该依赖这种行为!

According to RFC2145 (page 3),

RFC791 [4] defines the "robustness principle" in section 3.2:

an implementation must be conservative in its sending behavior, and liberal in its receiving behavior.

This principle applies to HTTP, as well. It is the fundamental basis for interpreting any part of the HTTP specification that might still be ambiguous. In particular, implementations of HTTP SHOULD NOT reject messages or generate errors unnecessarily.

And in particular:

It is, and has always been, the explicit intent of the HTTP specification that an implementation receiving a message header that it does not understand MUST ignore that header.

So the server is ignoring the version number in the case that it's "Http1.1" (which is not valid) and presumably it's interpreting the message as a HTTP/1.0 message (or maybe even HTTP/0.9!). Of course, you should not rely on this behaviour!

白况 2024-09-09 23:51:30

应该是

GET /http.html HTTP/1.1

It should be

GET /http.html HTTP/1.1
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文