I'm trying to push out a notification to the C2DM server with node.js, but I'm getting nothing. Trying port 80 yields a 404, while trying port 143 yields nothing.
I've successfully run this curl command:
curl --header "Authorization: GoogleLogin auth=[auth cookie]" "https://android.apis.google.com/c2dm/send" -d registration_id=[reg id] -d "data.payload=payload" -d collapse_key=0
but, while appearing to be similar, I can't get the node.js counterpart to work. Any ideas?
var querystring = require('querystring');
var http = require('http');
var post_domain = 'https://android.apis.google.com';
var post_port = 143;
var post_path = '/c2dm/send';
var post_data = querystring.stringify({
'registration_id' : '[reg id]',
'collapse_key': '0' ,
'data.payload' : 'Hello!'
});
var post_options = {
host: post_domain,
port: post_port,
path: post_path,
method: 'POST',
headers: {
'Authorization: GoogleLogin auth': '[auth cookie]'
}
};
var post_req = http.request(post_options, function(res) {
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('Response: ' + chunk);
});
});
// write parameters to post body
post_req.write(post_data);
post_req.end();
You should take a look at Instagram's library for pushing messages to C2DM: https://github.com/Instagram/node2dm