我能使用CURL获取HTTP/2标头吗?

Oru*_*run 5 curl http serving http2

现在我curl -I用来检索标题.

在即将采用的浏览器采用HTTP/2时,网站会采用不同的方式为HPACK提供标头,这会使我对curl命令的使用无效吗?

Dan*_*erg 7

是的,您可以像使用 HTTP/1 一样使用 curl 查看和发送带有 HTTP/2 的 HTTP 标头。

curl 支持 HTTP/2,它被实现为一种翻译层。这意味着它显示并“假装”标题使用 1.1 样式。它将标题显示为文本,并在回调中发送标题,就像它们在 1.1 中所做的那样。我们通过这种方式使脚本和应用程序通过 curl 获得了到 HTTP/2 的非常平滑且基本上不可见的转换路径。

在内部,这当然是通过在显示之前解压缩接收到的标头来完成的,并在发送它们时在压缩它们之前显示它们。


p4g*_*uru 5

我相信这取决于卷曲版本.在curl 7.36.x IIRC中添加了HTTP/2?并非所有的发行版都有这个版本?

这是针对https://google.com的 HTTP/2卷曲7.41.0

curl --http2 -I -v https://google.com
* Rebuilt URL to: https://google.com/
*   Trying 173.194.123.1...
* Connected to google.com (173.194.123.1) port 443 (#0)
* ALPN, offering h2-14, http/1.1

* ALPN, server accepted to use h2-14
* Server certificate:
*        subject: C=US; ST=California; L=Mountain View; O=Google Inc; CN=*.google.com
*        start date: 2015-03-11 16:13:43 GMT
*        expire date: 2015-06-09 00:00:00 GMT
*        subjectAltName: google.com matched
*        issuer: C=US; O=Google Inc; CN=Google Internet Authority G2
*        SSL certificate verify ok.
* Using HTTP2    
Run Code Online (Sandbox Code Playgroud)

编辑:更正,卷曲--http2需要编译为nghttp2工作https://nghttp2.org/

curl --version 
curl 7.41.0 (x86_64-unknown-linux-gnu) libcurl/7.41.0 OpenSSL/1.0.2b zlib/1.2.8 nghttp2/0.7.8-DEV
Protocols: dict file ftp ftps gopher http https imap imaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp 
Features: AsynchDNS IPv6 Largefile NTLM NTLM_WB SSL libz TLS-SRP HTTP2 UnixSockets 
Run Code Online (Sandbox Code Playgroud)