【问题标题】:HTTP: leading blank line in header - a valid http request header?HTTP:标头中的前导空白行-有效的http请求标头?
【发布时间】:2018-04-06 01:54:14
【问题描述】:

只是想知道,这是一个有效的 http 请求,请在实际请求标头之前记下前导空行“\r\n”。

\r\n\r\nGET / HTTP/1.0\r\n\r\n

尽管它适用于所有服务器(apache、lighttpd、nginx),但 RFC 并没有强制要求任何关于前导空行的内容,并将其留给实现。

谢谢

【问题讨论】:

    标签: apache http nginx https http-headers


    【解决方案1】:

    因此标准规定每个新行应以\r\n 结尾,每个请求应以\r\n\r\n 结尾

    What, at the bare minimum, is required for an HTTP request?

    但大多数服务器将处理大多数类型的前导换行符

    printf '\rGET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: close\r\n\r\n' |
      nc www.example.com 80
    printf '\r\nGET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: close\r\n\r\n' |
      nc www.example.com 80
    printf '\r\r\nGET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: close\r\n\r\n' |
      nc www.example.com 80
    printf '\n\rGET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: close\r\n\r\n' |
      nc www.example.com 80
    

    关于是否有效,网上的很多东西都是 100% 符合 RFC 标准的。也可以看看

    https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol

    所以一个空格会在开始时产生问题,但许多服务器会删除前导空白新行

    【讨论】:

      猜你喜欢
      • 2017-10-07
      • 2015-07-13
      • 1970-01-01
      • 1970-01-01
      • 2012-01-06
      • 1970-01-01
      • 2019-01-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多