1
我想使用node.js将POST请求包装到Parse中。我只想发送推送通知,但套接字挂起错误不断显示。在node.js post请求中套接字挂起错误
这是解析推REST API文档:https://www.parse.com/docs/push_guide#top/REST
它使用curl和python做的工作。这是我检查做翻译教程:http://tech.pro/tutorial/1091/posting-json-data-with-nodejs
这是我的代码:
var http = require('http')
var data = {
channels: 'a_channel',
data: {
alert: "Something has happened"
}
}
pdata = JSON.stringify(data);
var apiKeys = {
"X-Parse-Application-Id": "lol",
"X-Parse-REST-API-Key": "lolol",
"Content-Type": "application/json",
'Content-Length': pdata.length
};
var options = {
hostname: 'api.parse.com',
port: 443,
path: '/1/push',
method: 'POST',
headers: apiKeys
};
var req = http.request(options, function(res) {
res.setEncoding('utf-8');
var responseString = '';
res.on('data', function(data) {
responseString += data;
});
res.on('end', function() {
var resultObject = JSON.parse(responseString);
});
});
req.on('error', function(e) {
console.log('problem with the request, wero: ' + e.message);
});
req.write(pdata);
req.end();
console.log(pdata);
谢谢!