Call the google fcm HTTP v1 API to send a group push to Android devices and receive a 411 error.

call the google fcm HTTP v1 API to send a group push to Android devices and receive 411. Http header does not have a content-length error, but I specified content-length in curl.

    $topic = "topic";
    $projectId = "projectid";
    $title = "hahaha";
    $content = "lol";

    $payload = array(
        "message" => array(
            "topic" => $topic,
            "notification" => array(
                "title" => $title,
                "body" => $content,
            )
        )
    );

    $json = json_encode(trim($payload));
    $headers = array(
        "Authorization:Bearer ".$this->getFcmApiAccessToken(),
        "Content-Type: application/json; UTF-8",
        "Content-length:".strlen($json),//"Content-length:0"
    );

    $ch = curl_init();
        
  
  
 curl_setopt($ch,CURLOPT_URL,"https://fcm.googleapis.com/v1/projects/{$projectId}/messages:send");
    curl_setopt($ch,CURLOPT_POST, true );
    curl_setopt($ch,CURLOPT_HEADER, 1);
    curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch,CURLOPT_POSTFIELDS, $json);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);

    $result = curl_exec($ch);
    curl_close($ch);

    var_dump($result);exit;
Mar.13,2021

$this- > getFcmApiAccessToken (), can I see how you get token here?

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b38044-2c0d2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b38044-2c0d2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?