Click here to Skip to main content
14,301,191 members
Rate this:
Please Sign up or sign in to vote.
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".

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, "");
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?
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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100