我想通過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