在Node.js中进行REST调用,需要客户端证书进行身份验证 [英] Making a REST call in Node.js that requires client certificate for authentication
本文介绍了在Node.js中进行REST调用,需要客户端证书进行身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有一种方法可以通过Node.js进行需要客户端证书进行身份验证的休眠调用?
Is there a way to make a rest call that requires a client certificate for authentication through Node.js ?
推荐答案
是,你可以这么做,这里使用常规的https请求;
Yes, you can do that quite simply, here done using a regular https request;
var https = require('https'), // Module for https
fs = require('fs'); // Required to read certs and keys
var options = {
key: fs.readFileSync('ssl/client.key'), // Secret client key
cert: fs.readFileSync('ssl/client.crt'), // Public client key
// rejectUnauthorized: false, // Used for self signed server
host: "rest.localhost", // Server hostname
port: 8443 // Server port
};
callback = function(response) {
var str = '';
response.on('data', function (chunk) {
str += chunk;
});
response.on('end', function () {
console.log(str);
});
}
https.request(options, callback).end();
这篇关于在Node.js中进行REST调用,需要客户端证书进行身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文