2014-01-06 58 views
0

伙计们我无法请求此网址..这看起来很好,但我总是收到错误ECONNRESET。ECONNRESET错误node.js https

我写了一个红宝石的脚本,它工作正常。与在终端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); 
}); 

回答

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); 
} 
相关问题