使用 cURL 连接到 Apple 的 APNS,通过 nghttp2 支持 HTTP\2



我试图按照本教程编译支持 HTTP/2 的 cURL。我正在使用Docker,我的应用程序基于官方的PHP Docker镜像,它使用Debian,尽管我在Vagrant VM中运行的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时,问题就开始了,该API现在在HTTP/2上运行。

我已经在我的Mac上通过Homebrew安装了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

我不确定为什么这个问题似乎是苹果服务特有的,以及需要做些什么来纠正这种情况。

任何帮助将胜感激!

对于将来看到这种情况的任何人,我最终解决了这个问题,答案是服务器故障。

这里的问题是,OpenSSL/1.0.1k没有附带ALPN协议。

苹果需要它,而 https://nghttp2.org 对NPN感到满意。

因此,要解决此问题,请让 OpenSSL/1.0.2 工作,一切就绪。

最新更新