How to do HTTPS GET with client certificate in node

后端 未结 1 1490
醉话见心
醉话见心 2020-12-10 04:42

I can use curl for making a GET request ->

`curl -v https://example.com:82/v1/api?a=b` -E client_cert.pem:password 

How can I use same in n

相关标签:
1条回答
  • 2020-12-10 05:41

    This worked for me -

    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()
    
    0 讨论(0)
提交回复
热议问题