【问题标题】:Will I be able to use CURL to get HTTP/2 headers?我可以使用 CURL 来获取 HTTP/2 标头吗?
【发布时间】:2015-04-26 12:56:22
【问题描述】:

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

在即将被浏览器采用的 HTTP/2 中,网站是否会采用不同的方式通过 HPACK 提供标头,这会使我对 curl 命令的使用无效?

【问题讨论】:

    标签: http curl serving http2


    【解决方案1】:

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

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

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

    【讨论】:

      【解决方案2】:

      我相信这取决于 curl 版本。在 curl 7.36.x IIRC 中添加了 HTTP/2?不是所有发行版都有那个版本?

      这是 curl 7.41.0 over HTTP/2 针对https://google.com

      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    
      

      编辑:更正,curl --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 
      

      【讨论】:

      • @Daniel Stenberg 是 cURL 项目的作者 :)
      猜你喜欢
      • 2017-07-25
      • 1970-01-01
      • 1970-01-01
      • 2012-01-09
      • 2012-04-21
      • 2011-06-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多