samedi 7 mars 2015

Error: socket hang up using node v0.12.0

I'm trying to perform a very simple HTTP POST with Node:



var querystring = require('querystring');
var http = require('http');

var postData = querystring.stringify({
"source": "XXXX",
"target": "XXXX",
"create_target": true,
"continuous": false
});

var options = {
hostname: 'XXXX',
port: 443,
path: '/_replicate',
method: 'POST',
headers: {
'Content-Type:':'application/json',
'Content-Length':Buffer.byteLength(postData)
}
};

var req = http.request(options, function(res) {
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('BODY: ' + chunk);
});
});

req.on('error', function(e) {
console.log('problem with request: ' + e.stack);
});

req.write(postData);
req.end();


But the response I get is this:



problem with request: Error: socket hang up
at createHangUpError (_http_client.js:215:15)
at Socket.socketOnEnd (_http_client.js:293:23)
at Socket.emit (events.js:129:20)
at _stream_readable.js:908:16
at process._tickCallback (node.js:355:11)


I'm using node v0.12.0.




I have seen these other similar questions on Stackoverflow, but I believe them to be different because:



Aucun commentaire:

Enregistrer un commentaire