带 CURL 的 HTTP2 给出 "Unsupported Protocol"

HTTP2 with CURL gives "Unsupported Protocol"

已经按照 here 中的步骤进行操作,我在使用 curl --http2 选项时仍然有 Unsupported Protocol。同样,将 CURLOPT_HTTP_VERSION 设置为 CURL_HTTP_VERSION_2_0 会导致程序使用 HTTP/1.1 而不是 HTTP/2.

进行通信

平台:UbuntuVMware Player 7 上的 15.04。

我用 --prefix=/usr/local 安装了 nghttp2-1.0.4,因此 libnghttp2.* 位于 /usr/local/lib.

这是配置 curl-7.43.0 的代码:

./configure --with-nghttp2=/usr/local

结果显示启用了HTTP2:

    HTTP2 support:    enabled (nghttp2)

makesudo make install之后,下面的returnsUnsupported Protocol

curl --http2 https://http2.akamai.com

curl 版本未显示支持 nghttp2:

curl 7.43.0 (i686-pc-linux-gnu) libcurl/7.38.0 OpenSSL/1.0.1f zlib/1.2.8 libidn/1.28 librtmp/2.3
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp smtp smtps telnet tftp 
Features: AsynchDNS IDN IPv6 Largefile GSS-API SPNEGO NTLM NTLM_WB SSL libz TLS-SRP

然后我听从了 的建议,我需要有 OpenSSL 1.0.2 或更高版本。在 /opt/openssl 中安装后,我重新配置:

./configure --with-nghttp2=/usr/local --with-ssl=/opt/openssl/lib

makesudo make install之后,所有问题都一样。奇怪的是,curl --version还是returns和上面一样的信息,OpenSSL/1.0.1f还没有升级。

非常感谢任何帮助我成功使用 --http2 选项的帮助。

显然您没有链接正确版本的 curl,至少在运行时是这样。这就是输出 libcurl/7.38.0 的意思。我的版本号更高。尝试

LD_LIBRARY_PATH=/usr/local/lib curl <whatever> 

遵命。或者只是为了确定:

ldd `which curl` 

并注意列出的依赖项。

这个真的帮我正确设置了它

我发现 curl 7.53.1 for Windows 这个工具对于测试 http2 请求非常有用。 它有 pre-compiled 为 Windows 构建的 curl,支持 OpenSSL、ngttp2、zlib 和 IPv6。