我试图让客户端证书与我的api服务器通信。卷曲它工作正常。
nodejs@ip-10-1-59-225:/home/foouser$ curl --key /var/run/keys/key.pem --cert /var/run/certs/cert.pem -k -v https://api.myserver.com
但是,如果我尝试使用节点的相同示例,则不会。
const options = {
hostname: 'api.myserver.com',
port: 443,
path: '/',
method: 'GET',
rejectUnauthorized: false,
key: fs.readFileSync('/var/run/keys/key.pem'),
cert: fs.readFileSync('/var/run/certs/cert.pem')
};
const req = https.request(options, (res) => {
res.on('data', (data) => console.log(data));
});
req.on('error', (err) => console.log(err));
出现此错误
{ Error: socket hang up
at TLSSocket.onHangUp (_tls_wrap.js:1124:19)
at TLSSocket.g (events.js:292:16)
at emitNone (events.js:91:20)
at TLSSocket.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickCallback (internal/process/next_tick.js:104:9) code: 'ECONNRESET' }
关于可能出错的任何建议?