ECONNRESET错误node.js https

时间:2014-01-06 21:53:22

标签: node.js https econnreset

伙计我在请求此URL时遇到问题..看起来很好,但我总是得到错误ECONNRESET。

我在ruby中写了一个小脚本并且运行正常。终端中的cURL也可以使用。

我在很多问题上尝试了所有解决方案并堆栈溢出线程......像这样: https://github.com/joyent/node/issues/5360 https://github.com/joyent/node/issues/5119

知道它可能是什么吗?

网址为: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 个答案:

答案 0 :(得分:0)

你好吗?

让我们尝试这个解决方案。

app.js

更改选项:

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);
}