ECONNRESET error node.js https

1k views Asked by At

Guys I'm having trouble requesting to this URL.. It seems fine, but I always get the error ECONNRESET.

I wrote a little script in ruby and it worked fine. With cURL in the terminal also works.

I tried all the solutions on a lot of issues and stack overflow threads... Like these: https://github.com/joyent/node/issues/5360 https://github.com/joyent/node/issues/5119

Any idea what it might be?

The url is: https://ecommerce.cielo.com.br/servicos/ecommwsec.do

var https = require('https');

var options = {
host: 'ecommerce.cielo.com.br',
path: '/servicos/ecommwsec.do',
//This is what changes the request to a POST request
method: 'GET',
};

https.globalAgent.options.secureProtocol = 'SSLv3_method';

callback = function(response) {
var str = ''
response.on('data', function (chunk) {
str += chunk;
});

response.on('end', function () {
    console.log(str);
});
}

var req = https.request(options, callback);

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

There are 1 answers

0
Dsouza On

How are you ??

Let's try this solution.

app.js

Change your options:

var options = {
    host: 'ecommerce.cielo.com.br',
    path:'/servicos/ecommwsec.do',
    method: 'POST',
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
        'Content-Length': Buffer.byteLength(body),
        'user-agent': 'node.js'
    }
};

   https.globalAgent.options.secureProtocol = 'SSLv3_method';

 try{
    var req = https.request(options, function(res)
    {
        res.setEncoding('utf8');
        res.on('data', function (chunk) {
            console.log("body: " + chunk);
        }).on('end', function(cieloResponse){
            console.log( cieloResponse);
        });
        console.log('Response:' + res);
    });

    req.end();
}catch(err){
    console.log('ERRO: '+ err);
}