CURL HTTP2请求

Phi*_*ast 10 curl

我想知道是否有人成功设法使用CURL通过新的APNS API(HTTP2)发送推送通知.

APNs Provider API页面上给出的示例请求

这是请求必须如何:

HEADERS

\- END_STREAM

\+ END_HEADERS

:method = POST

:scheme = https

:path = /3/device/00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0

host = api.development.push.apple.com

apns-id = eabeae54-14a8-11e5-b60b-1697f925ec7b

apns-expiration = 0

apns-priority = 10

content-length = 33
Run Code Online (Sandbox Code Playgroud)

数据

\+ END_STREAM

{ "aps" : { "alert" : "Hello" } }
Run Code Online (Sandbox Code Playgroud)

但是使用以下命令我得到错误"curl:(16)HTTP/2流1没有干净地关闭:error_code = 8":

curl \

--verbose \

--http2 \

--cert <APPLICATION_CERT_FILE> \

--key <APPLICATION_KEY_FILE> \

--header "Content-Type: application/json" \

--header ":method: POST" \

--header ":path: /3/device/<DEVICE ID>" \

--data '{ "aps" : { "alert" : "Hello" } }' \

https://api.development.push.apple.com
Run Code Online (Sandbox Code Playgroud)

有小费吗?

rye*_*ead 11

我已成功使用以下命令从cURL发送推送通知:

curl -v -d '{"aps":{"alert":"Test Push","sound":"default"}}' \
--cert /path/to/cert/cert.pem:SECURE_PASSWORD \
-H "apns-topic: com.app.identifier" --http2 \
https://api.development.push.apple.com/3/device/DEVICE_ID
Run Code Online (Sandbox Code Playgroud)

这是使用由自制软件安装的curl版本:7.48.0

$ curl --version
curl 7.48.0 (x86_64-apple-darwin15.4.0) libcurl/7.48.0 OpenSSL/1.0.2g zlib/1.2.5 nghttp2/1.9.1
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp 
Features: IPv6 Largefile NTLM NTLM_WB SSL libz TLS-SRP HTTP2 UnixSockets 
Run Code Online (Sandbox Code Playgroud)

但请注意,我在生产服务器上使用开发证书时遇到的错误与以下相同: https://api.push.apple.com/

curl:(16)HTTP/2流1没有干净地关闭:error_code = 8


jud*_*ira 8

基于证书的提供者认证

curl -v
     -d '{"aps":{"alert":"hello"}}'
     -H "apns-topic: <your app bundle ID>" 
     --http2 
     --cert cert.pem
     https://api.push.apple.com/3/device/<device token>
Run Code Online (Sandbox Code Playgroud)

基于令牌的提供者身份验证

curl -v 
     -d '{"aps":{"alert":"hello"}}'
     -H "apns-topic: <your app bundle ID>" 
     -H "authorization: bearer xxxx.yyyy.zzzz" 
     --http2
     https://api.push.apple.com/3/device/<device token>
Run Code Online (Sandbox Code Playgroud)

您需要生成JWT令牌并使用ES256对其进行签名.这超出了范围(在Google快速搜索中很容易找到许多库).


Dan*_*erg 0

  1. 删除 --header ":method: POST" (--data 将使其使用 POST)

  2. 删除-header“:路径:/ 3 /设备/”

    :path 部分是您想要在 URL 中主机名右侧的部分,因此请指定一个 URL,例如https://api.development.push.apple.com/3/device/<DEVICE ID>

  3. 也就是说,获得这样的 HTTP/2 级别流错误是非常意外的,并且宁愿在某个地方指示较低级别的问题......