Can't send push notification - Unexpected HTTP/1.x request error

I am using PHP to send notifications from my server.

But it is not working, the program outputs "Unexpected HTTP/1.x request: GET /3/device/myDeviceToken" upon calling curl_exec().

No notification is received on my iOS device either.

This is the code:


token = getToken($keyfile, $kid, $iss);

$url="https://api.development.push.apple.com:443/3/device/".urlencode($to);
$curl = curl_init();
$headers = array("Content-Type:application/json", "authorization: bearer ".$token, "apns-expiration: 0", "apns-priority: 10", "apns-topic: balintfodor.locationconnection-test");
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, true);
$options = array($curl, array(  
  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($curl);
$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE); 
$err = curl_error($curl);

var_dump($httpcode, $result, $err); //int(0) bool(true) string(0) ""

Replies


<?PHP
if ( defined("CURL_VERSION_HTTP2") && (curl_version()["features"] & CURL_VERSION_HTTP2) !== 0) {

$entityBody = file_get_contents('php://input');
$jsonConvet = json_decode($entityBody,true);
$device_token = $jsonConvet["devicetoken"];
        $ch = curl_init();
        $body ['aps'] = array (
            "alert" => array (
                "status" => 1,
                "title"  => "source:123,destination:456",
                "body"   => "source:123,destination:456",
            ),
            "badge" => 1 ,
            "sound"  => "default"
        );
        $curlconfig = array(
            CURLOPT_URL => "https://api.development.push.apple.com/3/device/" . $device_token,
            CURLOPT_RETURNTRANSFER =>true,
            CURLOPT_POSTFIELDS => json_encode($body),
            CURLOPT_SSLCERT =>"VOIP.pem",
            CURLOPT_SSLCERTPASSWD => "123456789",
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_2_0,
            CURLOPT_VERBOSE => true
        );
        curl_setopt_array($ch, $curlconfig);
        $res = curl_exec($ch);
        if ($res === FALSE) {
                echo('Curl failed: ' . curl_error($ch));
        }
        else{
            echo('Curl success: ' . curl_error($ch));
        }
        curl_close($ch);
}
else{
        echo "No HTTP/2 support on client.";
    }
?>