Node.js休息呼叫到需要证书的服务器
答
解决方案是使用自定义connection pool,为此,您需要使用自定义Agent。
下面是一个使用标准https
模块为例,直from the documentation:
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's request,您可以设置在pool
选项自定义代理。
为什么我需要使用自定义代理和连接池? – micc0
代理管理套接字池并用于管理一次进程可以一次打开的套接字的最大数量默认情况下,所有HTTPS请求均使用https.globalAgent。 如[详细](http://nodejs.org/api/https.html#https_https_request_options_callback)所示,您可以将自己的证书信息提供给任何请求...但如果您使用全局代理,则这些选项将被忽略。您将需要使用自定义代理。 –
这听起来很有趣,但真的可以使用代码示例。 –