问题
I want to use http/2 with cURL. First I got an error when I tried this curl --http2 https://http2.akamai.com/
- "Protocol not supported". I installed nghttp2 and reinstalled cURL like it is described here. The error is gone and I can get data with the curl --http2
now. But the page https://http2.akamai.com/ tells me "This browser is not HTTP/2 enabled", while in chrome or directly via nghttp2 it says "You are using HTTP/2 right now!".
I'm using mac os x and installed all dependencies in the latest versions via homebrew. The curl sources (7.41) I downloaded here.
回答1:
You're probably not running the newly built curl, or your new curl build is using the previous libcurl install. Invoke 'curl --version
' and make sure it lists "HTTP2" as supported (included in Features).
You also need to make sure you build curl with an TLS library version that has support for ALPN (for HTTP/2 over TLS). If you build with openssl, you need version 1.0.2 (or later).
I just tried now on https://http2.akamai.com/ and it says "You are using HTTP/2 right now!" just fine when I try my curl build on it like this:
$ curl --http2 -kv https://http2.akamai.com/
You can view the verbose output and you should see the ALPN offer and what protocol curl and the server agree on using.
回答2:
The page is probably whitelisted for particular browsers that are HTTP/2 enabled, so it's returning a static content because it doesn't recognize the cURL one. You can set your user agent to pretend that you're Chrome, e.g.
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/
来源:https://stackoverflow.com/questions/29759380/curl-is-not-working-with-nghttp2