我正在尝试使用 php curl 将 json 数据发布到 GCM(Google Cloud Messaging)服务器。下面是我的代码片段
$url="https://android.googleapis.com/gcm/send";
$fields=array('registration_ids'=>$registration_ids,'data'=>$message);
$headers=array('Authorization:key='. GOOGLE_API_KEY,
'Content-Type:application/json',
'Content-Length: '.strlen(json_encode($fields)));
$ch=curl_init();
curl_setopt($ch,CURLOPT_CUSTOMREQUEST,"POST");
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch,CURLOPT_POSTFIELDS,json_encode(fields));
$result=curl_exec($ch);
curl_close($ch);
echo $result;
在运行此脚本时,我收到一条错误消息
Error 411(Length Required) !! 1
我搜索了几个论坛,但没有得到解决方案。任何人都可以帮忙吗?