【问题标题】:How to do HTTPS GET with client certificate in node如何在节点中使用客户端证书进行 HTTPS GET
【发布时间】:2016-05-30 10:15:04
【问题描述】:

我可以使用 curl 发出 GET 请求 ->

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

如何在节点中使用相同的。我尝试了请求,超级代理但无法通过证书。

提前致谢!

【问题讨论】:

    标签: node.js ssl curl npm certificate


    【解决方案1】:

    这对我有用 -

    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()
    

    【讨论】:

    • key.pem 文件是什么?
    • @KingJulien key.pem 是与主机 AFAIR 进行身份验证所需的私钥 :)
    • http 请求不需要私钥。它被服务器使用
    • @youneszeboudj 当您使用客户端证书来验证您的 https 请求时,它可以在客户端上使用
    猜你喜欢
    • 2012-09-28
    • 2017-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-12
    • 1970-01-01
    • 2014-01-29
    • 1970-01-01
    相关资源
    最近更新 更多