Hi i am sending IOS push notifications using apns and curl in php and getting this error message.
I also define 'CURL_HTTP_VERSION_2_0' but still getting this error:
Unexpected HTTP/1.x request: POST /3/device/
Here is my code:
$key_file = XXXXXX';
$secret = null;
$private_key = JWKFactory::createFromKeyFile($key_file, $secret, [
'kid' => '3W6B5LQQHX',
'alg' => 'ES256',
'use' => 'sig',
]);
$payload = [
'iss' => 'RUK725A7V4',
'iat' => time(),
];
$header = [
'alg' => 'ES256',
'kid' => $private_key->get('kid'),
];
$jws = JWSFactory::createJWSToCompactJSON(
$payload, $private_key, $header
);
if (!defined('CURL_HTTP_VERSION_2_0')) {
define('CURL_HTTP_VERSION_2_0', 3);
}
$http2_server = 'https://api.development.push.apple.com';
$app_bundle_id = 'com.MD.example';
$token = $device->device_id;
$url = "{$http2_server}/3/device/{$token}";
// headers
$headers = array(
"apns-topic: {$app_bundle_id}",
'Authorization: bearer ' . $jws
);
This is the curl actual curl request.
// other curl options
curl_setopt_array($http2ch, array(
CURLOPT_URL => $url,
CURLOPT_PORT => 443,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POST => TRUE,
CURLOPT_POSTFIELDS => $data,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_TIMEOUT => 30,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_HEADER => 1,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_2_0,
));
$result = curl_exec($http2ch);