Firebase 使用php curl从google fcm HTTP v1 api获取411错误响应
我正试图将通知从服务器推送到所有安卓设备,主题相同,称为Google firebase cloud messaging api,然而,http响应称,代表POST请求的411错误代码需要一个内容长度头,但我确实在http POST请求头中添加了内容长度。我在谷歌上搜索了这个问题,并尝试了几种方法,但它似乎不起作用。我使用php版本7.0。我使用postman发送请求,它做得很好,即使没有标题:content typeFirebase 使用php curl从google fcm HTTP v1 api获取411错误响应,firebase,http-headers,google-cloud-messaging,firebase-cloud-messaging,php-curl,Firebase,Http Headers,Google Cloud Messaging,Firebase Cloud Messaging,Php Curl,我正试图将通知从服务器推送到所有安卓设备,主题相同,称为Google firebase cloud messaging api,然而,http响应称,代表POST请求的411错误代码需要一个内容长度头,但我确实在http POST请求头中添加了内容长度。我在谷歌上搜索了这个问题,并尝试了几种方法,但它似乎不起作用。我使用php版本7.0。我使用postman发送请求,它做得很好,即使没有标题:content type $topic = 'topic'; $projectId = 'pr
$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;
标题应该是不区分大小写的,但是尝试使用
Content-Length
而不是Content-Length
@BobSnyder是的,我已经尝试过了,但不起作用,让我困惑的是,我可以发送请求,而不必在postman中命名内容长度,但我不能使用curl做同样的事情