如何让一个从Node.js的到需要进行身份验证证书的服务器REST调用?
Answer 1:
解决的办法是使用自定义的连接池 ,为此,你需要使用自定义代理 。
下面是使用标准的一个例子https
模块,直接从文档 :
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
选项。
文章来源: Node.js Rest call to a server that requires a certificate