我正在尝试通过requestjs使用badssl.com的自签名证书。 我使用node-ssl-root-cas来注入证书
这是代码&我一直都在收错。
var request = require('request');
var fs = require('fs');
var path = require('path');
var buffer = fs.readFileSync('bad.crt');
request.get({
url: 'https://self-signed.badssl.com/',
agentOptions:{
ca :buffer
}
},function responseHandle(error, response, body){
console.log(error);
});
我尝试像这样修改ssl-root-cas的根数组
var request = require('request');
var fs = require('fs');
var path = require('path');
var buffer = fs.readFileSync('bad.crt');
var cas = require('ssl-root-cas');
cas.push(buffer);
cas.inject();
request.get({
url: 'https://self-signed.badssl.com/'
},function responseHandle(error, response, body){
console.log(error);
});
在这两种情况下我都会遇到以下错误
{ [Error: unable to verify the first certificate] code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE' }
是否无法将自签名证书与节点js一起使用?