Click here to Skip to main content
15,913,722 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Am working on a push notification that makes user of C2DM. I have been able to obtain the users registration id, authentication token from Google. But when i try to send the message i receive this error from google "411. That’s an error. POST requests require a Content-length header".

PHP
function sendMessageToPhone($authCode, $deviceRegistrationId, $msgType, $messageText) {

$reg_id = $deviceRegistrationId; // Registration ID

$device_id = "1"; // Used in case there is multiple messages being sent

$headers = array('Authorization: GoogleLogin auth=' . $_SESSION['google'],'Content-   Length: 818');
$data = array('registration_id' => $reg_id, 'collapse_key' => 'ck_' . $device_id, 'data.arg' => $message);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://android.apis.google.com/c2dm/send");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

$response = curl_exec($ch);
echo "Reponse is ".$response;
}


how do i resolve this?
Posted
Comments
DaveAuld 26-Nov-11 12:30pm    
I don't know if that is a typo in the code above, but there are spaces in the Content-Length which will break the parser at the other end.
'Content- Length: 818'
Edem Kofi 27-Nov-11 3:12am    
its a typo

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900