我想通过PHP将我的服务器发送的消息发送到手机。 这里是我的代码:Google GCM服务器返回404错误
$apiKey = "AIxxxxxxxxxxxxxxxxxxxx";
$registrationIDs = array($c2dmId);
$url = "https://android.googleapis.com/gcm/send";
$headers = array(
'Authorization: key='.$apiKey,
'Content-Type: application/json'
);
$fields = array(
'collapse_key' => $collapseKey,
'data' => array(
"type" => $msgType,
"extra" => $msgExtra,
"uuid" => $uuid,
"user_id" => $userId),
'registration_ids' => $registrationIDs,
);
print (json_encode($fields));
echo "<br/>";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
$resultInfo = curl_getinfo($ch);
echo "resultinfo: $resultInfo <br>";
foreach ($resultInfo as $key => $value) {
echo "$key => $value <br>";
}
curl_close($ch);
die ("Result: $result");
其中$ c2dmId只是registrationId我发送到服务器的电话。因此,我得到(在$结果变量):
<HTML>
<HEAD>
<TITLE>Not Found</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Not Found</H1>
<H2>Error 404</H2>
</BODY>
</HTML>
我不知道为什么。谁能帮忙?文档没有说404代码的任何内容,所以我真的不知道发生了什么。
404表示您尝试连接的服务url不存在。 http://en.wikipedia.org/wiki/HTTP_404 – sunil 2012-07-12 12:10:21
嗯...我知道,但我真的不知道它为什么说这在我的情况。我从[链接](http://developer.android.com/guide/google/gcm/gcm.html)获得网址,所以它应该是好的,不是吗?我真的不知道为什么我会得到404 :( – anula 2012-07-12 12:48:48