如何啟用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命令使用
本文永久更新連結地址: