我正在使用 axios 连接到内部服务器。网络管理员给了我访问服务器的根证书链,但是当我提供它们时 axios 仍然给我一个错误。
const certBundle = [
fs.readFileSync(__dirname + '/certs/master.pem', 'ascii'),
fs.readFileSync(__dirname + '/certs/root.pem', 'ascii')
];
const agent = new https.Agent({
ca: certBundle
});
let response = await axios.post(req.body.request, {httpsAgent: agent});
axios 是否实际使用了这些证书?
最佳答案
看来这需要添加到全局 http 代理中。
const https = require('https');
https.globalAgent.options.ca = [
fs.readFileSync(__dirname + '/certs/master.pem'),
fs.readFileSync(__dirname + '/certs/root.pem')
];
添加之后,一切正常,axios 正在接受流量。
关于node.js - Axios 自签名证书错误,即使在提供证书时也是如此,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58529369/