手机版
你好,游客 登录 注册
背景:
阅读新闻

如何启用curl命令HTTP2支持

[日期:2016-01-19] 来源:winclient.cn  作者:Linux [字体: ]

当我们直接使用 curl 去请求一个 https 页面时,默认可以看到其默认返回的是 HTTP1.1 的 response。现在使用 HTTP2 的网站越来越多,技术也越来越成熟,如何启用 curl 命令 HTTP 2 支持就成为了一个问题。

curl -I https://nghttp2.org/

curl-with-http2-support-2

当我们试图用 http2 参数时,会返回一个未支持协议的「curl: (1) Unsupported protocol」错误:

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

curl-with-http2-support-3

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

curl --version

curl-with-http2-support-4

从上图中,我们可以看到当前 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

#编译安装nghttp2
git clone https://github.com/tatsuhiro-t/nghttp2.git
cd nghttp2
autoreconf -i
automake
autoconf
./configure
make
sudo make install

升级curl版本

cd ~
sudo apt-get build-dep curl

wget http://curl.haxx.se/download/curl-7.46.0.tar.bz2
tar -xvjf curl-7.46.0.tar.bz2
cd curl-7.46.0
./configure --with-nghttp2=/usr/local --with-ssl
sudo make && make install

echo '/usr/local/lib' > /etc/ld.so.conf.d/local.conf
ldconfig

升级完版本之后,我们再查看 curl 版本时会发布特性中会增加 HTTP2 功能支持。此时 –http2 参数就可以正常使用了:

curl-with-http2-support-5

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

测试curl with http2

我们再使用如下命令测试 winclient 主页看看:

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

返回结果如下:

curl-with-http2-support-6

curl用法:获取网站的header头及状态码  http://www.linuxidc.com/Linux/2015-11/125325.htm

Linux工具之curl与wget高级使用  http://www.linuxidc.com/Linux/2015-05/117381.htm

Ubuntu 用户安装下载器 cURL 7.36.0  http://www.linuxidc.com/Linux/2014-05/102269.htm

Linux curl使用简单介绍 http://www.linuxidc.com/Linux/2008-01/10891.htm

Unix下Curl的使用方法及常用功能记录分享 http://www.linuxidc.com/Linux/2012-08/69154.htm

curl命令使用 http://www.linuxidc.com/Linux/2014-09/107018.htm

本文永久更新链接地址http://www.linuxidc.com/Linux/2016-01/127588.htm

linux
相关资讯       curl命令  HTTP2 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款