nodejs https错误:套接字与本地主机挂起

我有这个小的代码片段的目标托pipe在本地主机上的端点

var https = require('https'); var options = { hostname: 'localhost', port: 443, path: '/', method: 'GET', agent: false }; var req = https.request(options, function(res) { console.log("statusCode: ", res.statusCode); console.log("headers: ", res.headers); res.on('data', function(d) { process.stdout.write(d); }); }); req.end(); req.on('error', function(e) { console.error(e); }); 

我总是得到错误:

{[错误:套接字挂断]代码:'ECONNRESET',sslError:undefined}

看起来,请求甚至不被端点接收,因为它没有被捕获,并且没有超时发生。

如果我从浏览器尝试https:// localhost之类的请求,则发送成功。

如果我只是将代码中的主机更改为诸如encrypted.google.com之类的东西,那么它也可以成功运行。

任何人都知道为什么会这样呢?

编辑 :我也试着添加像接受,用户代理等等的浏览器发送相同的头,但仍然无法正常工作

编辑2 :这是我login时出现的堆栈跟踪:

 Error: socket hang up at SecurePair.error (tls.js:1013:23) at EncryptedStream.CryptoStream._done (tls.js:705:22) at CleartextStream.read [as _read] (tls.js:496:24) at CleartextStream.Readable.read (_stream_readable.js:320:10) at EncryptedStream.onCryptoStreamFinish (tls.js:301:47) at EncryptedStream.g (events.js:180:16) at EncryptedStream.EventEmitter.emit (events.js:117:20) at finishMaybe (_stream_writable.js:360:12) at endWritable (_stream_writable.js:367:3) at EncryptedStream.Writable.end (_stream_writable.js:345:5) 

ECONNRESET意味着TCP连接意外closures,即。 某处中间协议。

但是你写的代码对我来说似乎还可以。

也许你遇到这个问题https://github.com/joyent/node/issues/5360

TL; DR:您可以尝试使用最新的节点版本和secureOptions: constants.SSL_OP_NO_TLSv1_2添加到您的options

更新 SSLv3被破坏, https ://access.redhat.com/articles/1232123; 也许沟ISS?