APNS with JWT Token - curl: (55) Failed sending HTTP POST request

Hi,

I am trying to send a push notification via PHP-curl and command-line curl for http2 but after trying possible methods I end up getting the same error response "curl: (55) Failed sending HTTP POST request"


Curl

Code Block curl -v -d '{"aps":{"alert":"Hello"},"yourCustomKey":"11"}' \
-H "Content-Type: application/json" -X POST \
--http2 https://api.development.push.apple.com/3/device/DEVICE_TOKEN \
-H ':method: POST' \
-H ':scheme: https' \
-H ':path: /3/device/DEVICE_TOKEN' \
-H 'authorization: bearer TOKEN' \
-H 'apns-id: b150795-35ea-4894-a289-85e343936cca' \
-H 'apns-push-type: alert' \
-H 'apns-expiration: 1609919807' \
-H 'apns-priority: 10' \
-H 'apns-topic: com.company.suffix' \
-H 'apns-collapse-id: 9cb3190c-6046-4b7c-8cf4-61c6d05fd724'



Output:


Code Block * Trying 17.188.138.73:443...
* Connected to api.development.push.apple.com (17.188.138.73) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
* CAfile: /etc/ssl/certs/ca-certificates.crt
CApath: none
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
* TLSv1.3 (IN), TLS handshake, Request CERT (13):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
* TLSv1.3 (IN), TLS handshake, Finished (20):
* TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.3 (OUT), TLS handshake, Certificate (11):
* TLSv1.3 (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384
* ALPN, server accepted to use h2
* Server certificate:
* subject: CN=api.development.push.apple.com; OU=management:idms.group.533599; O=Apple Inc.; ST=California; C=US
* start date: Apr 17 17:37:51 2019 GMT
* expire date: May 16 17:37:51 2021 GMT
* subjectAltName: host "api.development.push.apple.com" matched cert's "api.development.push.apple.com"
* issuer: CN=Apple IST CA 2 - G1; OU=Certification Authority; O=Apple Inc.; C=US
* SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Failed sending HTTP POST request
* Connection #0 to host api.development.push.apple.com left intact
curl: (55) Failed sending HTTP POST request


What is wrong with my CURL request?
Any hit would be helpful, thanks.
You don't seem to have a payload to send. Your curl command is missing the "--data" section.
Also, the URL you are using is an old one.

You may want to consult this article about sending push notifications using curl: https://developer.apple.com/documentation/usernotifications/sending_push_notifications_using_command-line_tools


Thanks for the reply, looks like I didn't post the full curl command, I am posting data as well, again I am getting the same error when using command line curl or PHP code.


Code Block
curl -v --data '{"aps":{"alert":"Hello"},"yourCustomKey":"11"}' \
-H "Content-Type: application/json" -X POST \
--http2 https://api.push.apple.com/3/device/DEVICE_TOKEN \
-H ':method: POST' \
-H ':scheme: https' \
-H ':path: /3/device/DEVICE_TOKEN' \
-H 'authorization: bearer TOKEN' \
-H 'apns-id: b150795-35ea-4894-a289-85e343936cca' \
-H 'apns-push-type: alert' -H 'apns-expiration: 1609919807' \
-H 'apns-priority: 10' -H 'apns-topic: com.company.suffix' \
-H 'apns-collapse-id: 9cb3190c-6046-4b7c-8cf4-61c6d05fd724'

Code Block
$url = "https://api.push.apple.com";
$headers = [
":method"=> 'POST',
":scheme" => "https",
":path"=> '/3/device/'.$devicetoken,
"host" => "api.push.apple.com",
"authorization" => 'bearer '.$bearerToken,
"apns-id" => Str::uuid()->toString(),
"apns-push-type"=> 'alert',
"apns-expiration" => Carbon::now()->addMinutes(15)->getTimestamp(),
"apns-priority" => 10,
"apns-topic" => 'com.company.suffix',
"apns-collapse-id" => Str::uuid()->toString()
];
foreach($headers as $header=>$value){
$flatHeaders [] = $header.": ".$value;
}
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_PORT, 443);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $sample_alert);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $flatHeaders);
$response = curl_exec($ch);
$httpcode = curl_getinfo($ch);
if ($response === FALSE) {
return [
'error' => curl_error($ch),
'response' => $response,
'httpcode' => $httpcode
];
// throw new \Exception("Curl failed: " . curl_error($ch));
}


APNS with JWT Token - curl: (55) Failed sending HTTP POST request
 
 
Q