对需要证书的服务器的Node.js Rest调用 [英] Node.js Rest call to a server that requires a certificate

查看:77
本文介绍了对需要证书的服务器的Node.js Rest调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从Node.js到需要身份验证证书的服务器进行剩余呼叫?

How do a make a rest call from Node.js to a server that requires a certificate for authentication?

推荐答案

解决方案是使用自定义连接池,您需要为其使用自定义的代理

The solution is to use a custom connection pool, for which you'll need to use a custom Agent.

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

Here's an example using the standard https module, straight 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的请求,则可以在pool选项.


And if you use mikeal's request, you can set the custom agent in the pool option.

这篇关于对需要证书的服务器的Node.js Rest调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆