连接到苹果的APNS使用cURL和HTTP\2支持通过nghttp2。

时间:2021-12-21 03:51:38

I've attempted to compile cURL with HTTP/2 support by following this tutorial. I'm using Docker and my application is based off the official PHP Docker image, which uses Debian, although I've produced the same problems in an Ubuntu machine running inside a Vagrant VM.

在本教程中,我尝试使用HTTP/2支持来编译cURL。我正在使用Docker,而我的应用程序是基于使用Debian的官方PHP Docker映像,尽管我在运行在一个流浪者VM里的Ubuntu机器中产生了同样的问题。

There appears to be no problem at first. Indeed, running curl --version shows everything I'd expect:

一开始似乎没有问题。实际上,运行curl——版本显示了我所期望的一切:

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 

Also, I can connect to https://nghttp2.org just fine:

另外,我可以很好地连接到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

The problems begin when trying to connect to Apple's recently re-launched APNS Provider API which now runs on HTTP/2.

当试图连接到苹果最近重新启动的APNS提供者API时,问题就开始了,该API现在在HTTP/2上运行。

I've installed curl via Homebrew on my Mac (using --with-nghttp2) and I can get the following (expected) response:

我在Mac电脑上安装了curl(使用-nghttp2),我可以得到以下(预期)响应:

curl -d 'Hello' --http2 https://api.push.apple.com/3/device/test
{"reason":"Forbidden"}

However, if I try to run the same command from within my Docker image, I get:

但是,如果我尝试在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

I'm unsure why this problems seems to be specific to Apple's service, and what needs to be done to remedy the situation.

我不确定为什么这些问题似乎是针对苹果的服务,以及需要做些什么来补救这种情况。

Any help would be greatly appreciated!

非常感谢您的帮助!

2 个解决方案

#1


0  

For anyone seeing this in the future, I ended up solving this, and the answer is on Server Fault.

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

#2


0  

Problem here is, that OpenSSL/1.0.1k doesn't come with ALPN protocol.

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

Apple requires it, whereas https://nghttp2.org is happy with NPN.

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

So to solve this, get OpenSSL/1.0.2 to work and you are all set.

因此,要解决这个问题,可以使用OpenSSL/1.0.2来工作,并且您都已经设置好了。

#1


0  

For anyone seeing this in the future, I ended up solving this, and the answer is on Server Fault.

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

#2


0  

Problem here is, that OpenSSL/1.0.1k doesn't come with ALPN protocol.

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

Apple requires it, whereas https://nghttp2.org is happy with NPN.

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

So to solve this, get OpenSSL/1.0.2 to work and you are all set.

因此,要解决这个问题,可以使用OpenSSL/1.0.2来工作,并且您都已经设置好了。