我想知道是否有人成功设法使用CURL通过新的APNS API(HTTP2)发送推送通知.
在APNs Provider API page上给出了示例请求
这是请求必须如何:
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
数据
\+ END_STREAM { "aps" : { "alert" : "Hello" } }
但是使用以下命令我得到错误“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
有小费吗?
解决方法
我已成功使用以下命令从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
这是使用由homebrew安装的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
但请注意,我在生产服务器上使用开发证书时遇到的错误与https://api.push.apple.com/相同
curl: (16) HTTP/2 stream 1 was not closed cleanly: error_code = 8