Node.jsrest调用需要证书的服务器

如何从Node.js到需要authentication证书的服务器进行rest调用?

解决scheme是使用自定义连接池 ,您需要使用自定义代理 。


以下是使用标准https模块的示例,直接从文档中find :

 var options = { hostname: 'encrypted.google.com', port: 443, path: '/', method: 'GET', key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'), cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem') }; options.agent = new https.Agent(options); var req = https.request(options, function(res) { ... } 

如果您使用mikeal的请求 ,则可以在pool选项中设置自定义代理。