我尝试按照 this tutorial 编译支持 HTTP/2 的 cURL .我正在使用 Docker我的应用程序基于 official PHP Docker image ,它使用 Debian,尽管我在 Vagrant 中运行的 Ubuntu 机器中产生了同样的问题。虚拟机。
一开始似乎没有问题。事实上,运行 curl --version
显示了我所期望的一切:
curl 7.47.1 (x86_64-pc-linux-gnu) libcurl/7.47.1 OpenSSL/1.0.1k zlib/1.2.8 libidn/1.29 libssh2/1.4.3 nghttp2/1.7.1 librtmp/2.3
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: IDN IPv6 Largefile NTLM NTLM_WB SSL libz TLS-SRP HTTP2 UnixSockets
另外,我可以连接到 https://nghttp2.org就好了:
curl --http2 -I https://nghttp2.org
HTTP/2.0 200
date:Mon, 15 Feb 2016 18:02:34 GMT
content-type:text/html
content-length:6680
last-modified:Thu, 11 Feb 2016 14:29:49 GMT
etag:"56bc9add-1a18"
link:</stylesheets/screen.css>; rel=preload; as=stylesheet
accept-ranges:bytes
x-backend-header-rtt:0.000581
server:nghttpx nghttp2/1.8.0-DEV
via:1.1 nghttpx
strict-transport-security:max-age=31536000
x-frame-options:SAMEORIGIN
x-xss-protection:1; mode=block
x-content-type-options:nosniff
当尝试连接到 Apple 最近重新启动的 APNS Provider API 时,问题就开始了。现在在 HTTP/2 上运行。
我已经通过 Homebrew 在我的 Mac 上安装了 curl(使用 --with-nghttp2
),我可以获得以下(预期的)响应:
curl -d 'Hello' --http2 https://api.push.apple.com/3/device/test
{"reason":"Forbidden"}
但是,如果我尝试从我的 Docker 镜像中运行相同的命令,我会得到:
curl -d 'Hello' --http2 https://api.push.apple.com/3/device/test
?@@?HTTP/2 client preface string missing or corrupt. Hex dump for received bytes: 504f5354202f332f6465766963652f746573742048545450
我不确定为什么这个问题似乎是 Apple 服务特有的,以及需要采取什么措施来补救这种情况。
如有任何帮助,将不胜感激!
最佳答案
对于将来看到此问题的任何人,我最终解决了这个问题,答案在 Server Fault 上.
关于linux - 通过 nghttp2 使用支持 HTTP\2 的 cURL 连接到 Apple 的 APNS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35416247/