简体   繁体   English

ECONNRESET错误node.js https

[英]ECONNRESET error node.js https

Guys I'm having trouble requesting to this URL.. It seems fine, but I always get the error ECONNRESET. 伙计们,我在请求此URL时遇到了麻烦。.看起来不错,但我总是收到错误ECONNRESET。

I wrote a little script in ruby and it worked fine. 我用红宝石写了一个小脚本,效果很好。 With cURL in the terminal also works. 在终端中使用cURL也可以。

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 我在很多问题和堆栈溢出线程上都尝试了所有解决方案...像这样: 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 网址是: 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);
});

How are you ?? 你好吗 ??

Let's try this solution. 让我们尝试这个解决方案。

app.js 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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM