这样?
[JavaScript] 纯文本查看 复制代码 const https = require('https');
https.globalAgent.options.ca = require('ssl-root-cas/latest').create();
https.get('https://www.baidu.com/',function(res){
let html = '';
res.on('data',function(data){
html += data;
console.log(html);
})
}).on('error',err=>console.log(err.message))
输出:
[Asm] 纯文本查看 复制代码 [Running] node "e:\code\test.js"
Needs latest SSL Root Certificate Authority data e:\code\node_modules\ssl-root-cas\ssl-root-cas-latest.js
Loading latest certificates from https://mxr.mozilla.org/nss/source/lib/ckfw/builtins/certdata.txt?raw=1
unable to verify the first certificate
Error: getaddrinfo ENOTFOUND mxr.mozilla.org
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:66:26) {
errno: 'ENOTFOUND',
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'mxr.mozilla.org'
}
undefined
Couldn't download the latest Root CAs, but it's not a big deal.
Use "require('ssl-root-cas')" instead of "require('ssl-root-cas/latest')"
[Done] exited with code=0 in 2.891 seconds
照提示换了
[JavaScript] 纯文本查看 复制代码 const https = require('https');
https.globalAgent.options.ca = require('ssl-root-cas').create();
https.get('https://www.baidu.com/',function(res){
let html = '';
res.on('data',function(data){
html += data;
console.log(html);
})
}).on('error',err=>console.log(err.message))
输出
[Asm] 纯文本查看 复制代码 [Running] node "e:\code\test.js"
unable to verify the first certificate
[Done] exited with code=0 in 0.408 seconds |