linux命令开启http,如何启用curl命令HTTP2支持

文章目录

[隐藏]

启用curl命令HTTP2支持

编译安装nghttp2

升级curl版本

测试curl with http2

f3a4933e3a2324a7103742bafe2453da.jpg

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

curl -I https://nghttp2.org/

63dd43a19d2c8d7e2c8fbcd55957dbf8.jpg

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

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

158c947f4e531df60c5c6b35e387b394.jpg

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

curl --version

2ef058d0e5ebfd175db0f12739355753.jpg

从上图中,我们可以看到当前 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 参数就可以正常使用了:

8f3e43f6dae330e9560bd166637ba163.jpg

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

测试curl with http2

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

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

返回结果如下:

851671e5f536f1daf51e761991266a09.jpg

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

原文出处:linuxidc -> http://www.linuxidc.com/Linux/2016-01/127588.htm

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值