且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在节点中使用客户端证书进行HTTPS GET

更新时间:2023-01-13 08:31:57

这对我有用-

var https = require('https');
var fs  = require('fs');

var options = {
  hostname: 'example.com',
  port: 83,
  path: '/v1/api?a=b',
  method: 'GET',
  key: fs.readFileSync('/path/to/private-key/key.pem'),
  cert: fs.readFileSync('/path/to/certificate/client_cert.pem'),  
  passphrase: 'password'
};

var req = https.request(options, function(res) {
console.log(res.statusCode);
res.on('data', function(d) {
  process.stdout.write(d);
  });
});

req.end()