如何啟用curl命令HTTP2支援

來源:互聯網
上載者:User

如何啟用curl命令HTTP2支援

當我們直接使用 curl 去請求一個 https 頁面時,預設可以看到其預設返回的是 HTTP1.1 的 response。現在使用 HTTP2 的網站越來越多,技術也越來越成熟,如何啟用 curl 命令 HTTP 2 支援就成為了一個問題。

curl -I https://nghttp2.org/

當我們試圖用 http2 參數時,會返回一個未支援協議的「curl: (1) Unsupported protocol」錯誤:

curl --http2 -I https://nghttp2.org/

使用如下命令我們可以看到 curl 版本:

curl --version

從中,我們可以看到當前 curl 的版本及支援的協議以及功能特性沒有支援 HTTP2。

啟用curl命令HTTP2支援編譯安裝nghttp2

為了讓 curl 支援 HTTP2 我們需要安裝 nghttp2(http2 的 C 語言庫):

#安裝編譯工具等sudo apt-get install git g++ make binutils autoconf automake autotools-dev libtool pkg-config \  zlib1g-dev libcunit1-dev libssl-dev libxml2-dev libev-dev libevent-dev libjansson-dev \  libjemalloc-dev cython python3-dev python-setuptools#編譯安裝nghttp2git clone https://github.com/tatsuhiro-t/nghttp2.gitcd nghttp2autoreconf -iautomakeautoconf./configuremakesudo make install
升級curl版本
cd ~sudo apt-get build-dep curlwget http://curl.haxx.se/download/curl-7.46.0.tar.bz2tar -xvjf curl-7.46.0.tar.bz2cd curl-7.46.0./configure --with-nghttp2=/usr/local --with-sslsudo make && make installecho '/usr/local/lib' > /etc/ld.so.conf.d/local.confldconfig

升級完版本之後,我們再查看 curl 版本時會發布特性中會增加 HTTP2 功能支援。此時 –http2 參數就可以正常使用了:

curl --http2 -I https://nghttp2.org
測試curl with http2

我們再使用如下命令測試 winclient 首頁看看:

curl --http2 -I https://www.winclient.cn

返回結果如下:

curl用法:擷取網站的header頭及狀態代碼 

Linux工具之curl與wget進階使用 

Ubuntu 使用者安裝下載器 cURL 7.36.0 

Linux curl使用簡單介紹

Unix下Curl的使用方法及常用功能記錄分享

curl命令使用

本文永久更新連結地址:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.