cURL 不适用于 nghttp2

标签 curl http2 nghttp2

我想将 http/2 与 cURL 一起使用。首先,当我尝试此 curl --http2 https://http2.akamai.com/ 时,出现错误 - “协议(protocol)不受支持”。我安装了 nghttp2 并重新安装了 cURL,就像描述的那样 here 。错误消失了,我现在可以使用 curl --http2 获取数据。但页面https://http2.akamai.com/告诉我“此浏览器未启用 HTTP/2”,而在 chrome 中或直接通过 nghttp2 则显示“您现在正在使用 HTTP/2!”

我使用的是 mac os x 并通过 homebrew 安装了最新版本中的所有依赖项。我下载的curl源代码(7.41)here .

最佳答案

您可能没有运行新构建的curl,或者您的新curl 构建正在使用以前的libcurl 安装。调用“curl --version”并确保它将“HTTP2”列为受支持(包含在功能中)。

您还需要确保使用支持 ALPN(针对基于 TLS 的 HTTP/2)的 TLS 库版本构建curl。如果您使用 openssl 构建,则需要版本 1.0.2(或更高版本)。

我刚刚尝试过 https://http2.akamai.com/它显示“您现在正在使用 HTTP/2!”当我像这样尝试在其上构建 curl 时就很好:

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

您可以查看详细输出,并且您应该看到 ALPN 报价以及curl 和服务器同意使用的协议(protocol)。

关于cURL 不适用于 nghttp2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29759380/

相关文章:

python - 带有 python -c "python code here"命令返回参数的 cURL 命令

curl - 有什么方法可以让curl 连接并让我在打字时输入并发送正文片段吗?

php - HTTP2 和继续执行 PHP

php - 使用 php 和 cURL 转发多部分表单数据

php - WooCommerce Rest API 给出语法错误

performance - 有没有像 fiddler 这样支持 http2 的工具?

IIS/Windows Server 2019 没有 HTTP/2

apache - 无法向 Apache 服务器发出 http2 请求,尽管服务器在响应 header 中发送 "Upgrade:h2"

swift - 如何使用 Alamofire 将 CURL 请求转换为 Swift?