CURL HTTP2 Request

I would like to know if someone was able to successfully send a push notification through the new APNS API (HTTP2) using CURL.

Sample request submitted on APNs provider API page

Here's how the request should 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 the 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?

+5
source share
3 answers

I 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 used by 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 

Please note that I get the same error as 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

+3
source

Certificate Provider Authentication

 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> 

Token Based Provider Authentication

 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 a JWT token and sign it using ES256. There is not enough space (it’s easy to find many libraries for quick Google search).

+2
source
  • remove --header ": method: POST" (--data will use POST)

  • remove -header ": path: / 3 / device /"

    Part of the path: this is what you want on the right side of the hostname in the url, so provide a url like https://api.development.push.apple.com/3/device/<DEVICE ID>

  • Thus, getting an HTTP / 2 layer stream error like this is very unexpected and would rather indicate a lower level problem somewhere ...

0
source

Source: https://habr.com/ru/post/1243750/


All Articles