mercredi 25 février 2015

Node.js ECONNRESET error

I tried the code below on BOTH Windows 7 and Mac Snow Leopard and I received the same error with Node.js 0.12.0


I have other port numbers, I have tried using 'localhost' instead of '127.0.0.1'. I have the IP in my host file under C:\Windows\System32. I am at a loss here but the behavior is consistent and I am seeing lots of chatter on the web with no REAL answers or solutions but people here get solid answers.


Response from Node.js command prompt



{ [Error: connect ECONNREFUSED]
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect' }
{ [Error: socket hang up] code: 'ECONNRESET' }


Code



var http = require('http');

var makeRequest = function(message) {
var options = {
host: '127.0.0.1', port: 8080, path: '/', method: 'POST', headers: {
'Content-Type': 'application/text',
'Content-Length': message.length
}
}

var request = http.request(options, function(response) {
response.on('data', function(data) {
console.log(data);
});
});

process.on('uncaughtException', function (err) {
console.log(err);
});

request.write(message);
request.end();
}

makeRequest('Hi!!!!');

Aucun commentaire:

Enregistrer un commentaire