I would like to know if someone successfully managed to send a push notification through the new APNS API (HTTP2)using CURL.
An example request's given on the APNs Provider API page
Here's how the request must be:
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
DATA
\+ END_STREAM
{ "aps" : { "alert" : "Hello" } }
But with the following command I get error "curl: (16) HTTP/2 stream 1 was not closed cleanly: 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
Any tips?
I have successfully sent push notifications from cURL using the following:
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
This is using curl
version 7.48.0
, installed by homebrew:
$ 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
Notice, however, that I get the same error as you do when using our development certificate on the production server: https://api.push.apple.com/
curl: (16) HTTP/2 stream 1 was not closed cleanly: error_code = 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>
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>
You will need to generate your JWT token and sign it using ES256. This is out of scope here (it's easy to find many libraries on a quick Google search).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With