cURL 不适用于 nghttp2

cURL is not working with nghttp2

我想将 http/2 与 cURL 一起使用。首先,当我尝试 curl --http2 https://http2.akamai.com/ - "Protocol not supported" 时出现错误。我安装了 nghttp2 并重新安装了 cURL,就像描述的那样 here. The error is gone and I can get data with the curl --http2 now. But the page https://http2.akamai.com/ 告诉我 "This browser is not HTTP/2 enabled",而在 chrome 中或直接通过 nghttp2 它说“您现在正在使用 HTTP/2!

我正在使用 mac os x 并通过自制软件在最新版本中安装了所有依赖项。我下载的 curl 源 (7.41) here.

该页面可能已针对启用 HTTP/2 的特定浏览器列入白名单,因此它返回静态内容,因为它无法识别 cURL 内容。您可以 set your user agent 假装自己是 Chrome,例如

curl -A "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/41.0.742.112 Safari/534.30" --http2 https://http2.akamai.com/

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

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

我刚刚在 https://http2.akamai.com/ 上尝试过,它说 "You are using HTTP/2 right now!" 很好,当我像这样尝试我的 curl 构建时:

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

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