将 --http2.0 选项与 curl 7.33.0 一起使用会提供不受支持的协议

Posted

技术标签:

【中文标题】将 --http2.0 选项与 curl 7.33.0 一起使用会提供不受支持的协议【英文标题】:using --http2.0 option with curl 7.33.0 gives unsupported protocol 【发布时间】:2013-12-05 16:27:28 【问题描述】:

我使用的是 centos 6.2,我需要在其中一个服务器请求中使用 curl --http2.0,但我使用的是 7.19.6,在查看 http://curl.haxx.se/docs/manpage.html 后,我发现 --http2.0 选项是仅支持 curl 7.33.0,所以为了解决这个问题,我按照http://www.linuxfromscratch.org/blfs/view/svn/basicnet/curl.html 的步骤安装了 curl 7.33.0 安装 curl 后,我尝试使用它,但它仍然给我错误 curl(1):unsupported protocol,我使用以下命令检查了我的 curl 版本:curl --版本这是给我的:

curl 7.33.0 (x86_64-unknown-linux-gnu) libcurl/7.33.0 OpenSSL/1.0.0 zlib/1.2.3
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smtp smtps telnet tftp 
Features: AsynchDNS IPv6 Largefile NTLM NTLM_WB SSL libz 

我需要使用这个 --http2.0 但没有得到任何我能做到的东西? 由于安装了 curl 7.19,并且我重新安装了更高版本的 curl,这有什么问题吗?

【问题讨论】:

【参考方案1】:

正如 Daniel on the mailing list 所解释的:

我的计划是将 http2 工作基于 nghttp2 库 (https://github.com/tatsuhiro-t/nghttp2) [...] HTTP2 将作为 libcurl 术语中的“功能”开始,而不是专门作为单独的协议。

所以首先你需要手动安装nghttp2[1]。

然后您需要在配置时使用--with-nghttp2 显式启用 HTTP2 支持:

./configure --with-nghttp2=/path/to/nghttp2/install/dir [...]

[1]:在编写 README 时声明它没有打包在 Ubuntu 中,因此您需要自己构建它

编辑

请在下面找到使用默认选项仅构建库(不是命令行工具)的基本说明。

要构建 nghttp2,您首先需要安装它的要求(详见nghttp2 documentation page):

# To clone the nghttp2 Github repo
yum install git

# Build essentials
yum install gcc
yum install make
yum install automake
yum install libtool

# Required to build the library
yum install pkgconfig
yum install zlib-devel

一旦完成克隆 repo:

git clone https://github.com/tatsuhiro-t/nghttp2.git
cd nghttp2

按照here 的说明构建库:

autoreconf -i
automake
autoconf
# Note: I assume you want to deploy it under /usr/local
# Feel free to adapt to your needs!
./configure --prefix=/usr/local
make

然后部署它:

make install

如果一切正常,您需要通过注意使用./configure --with-nghttp2=/usr/local [...] 启用 nghttp2 来构建 libcurl 7.33.0。

附加功能

如果您想另外构建应用程序(nghttp,...),您必须在构建 nghttp2 之前安装其他软件包:

yum install openssl-devel
yum install libevent-devel
yum install libxml2-devel
yum install jansson-devel

【讨论】:

我无法安装它,你能给我一步一步的安装说明吗,因为我是 linux 的新手...感谢支持 如果可能,请提供其他所需软件的说明以支持它 我已经使用 nghttp2 库构建说明编辑了我的问题。 autoreconf -i 给我的错误是:perl:警告:设置语言环境失败。 perl: 警告: 请检查您的语言环境设置:LANGUAGE = (unset), LC_ALL = (unset), LC_CTYPE = "UTF-8", LANG = "en_US.UTF-8" 是否支持并安装在您的系统上。 perl:警告:回退到标准语言环境(“C”)。 configure.ac:205:警告:在库 autoreconf 中找不到宏“AM_PATH_XML2”:/usr/bin/autoconf 失败,退出状态:1 太棒了!我已经用可能需要的额外软件包再次编辑了我的答案(特别是libxml2-devel,我假设你已经安装它来修复你的配置错误)。

以上是关于将 --http2.0 选项与 curl 7.33.0 一起使用会提供不受支持的协议的主要内容,如果未能解决你的问题,请参考以下文章

http2协议之底层原理抓包分析与视频讲解

当网宿MAA与HTTP2.0双剑合璧后

Apache HTTP2 h2c 模式无法正常工作

HTTP2.0 简介

Java9 HTTP2.0 API入门与实践

HTTP 2.0与OkHttp