node.js报错
本帖最后由 55229lwj 于 2022-7-24 14:25 编辑# https模块访问url报错
代码如下
```
const https = require('https');
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))
```
输出
```
node "e:\code\test.js"
'unable to verify the first certificate'
exited with code=0 in 1.618 seconds
```
在别的电脑上可以运行,百度半天也解决不了
测试电脑是win7的
node.js版本:v12.22.12
请问各位大佬有无解决方案? 替你百度了,检查下是否使用了代{过}{滤}理 会不会是后台或者服务器的问题呢 require('https').globalAgent.options.ca = require('ssl-root-cas/latest').create();
加上这段代码试一下 估计是后台服务器问题 本帖最后由 baichenyi 于 2022-7-22 11:11 编辑
https://blog.csdn.net/weixin_34301132/article/details/91935155?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1-91935155-blog-106438611.pc_relevant_multi_platform_whitelistv3&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1-91935155-blog-106438611.pc_relevant_multi_platform_whitelistv3&utm_relevant_index=2 后台服务问题 cube 发表于 2022-7-22 10:55
替你百度了,检查下是否使用了代{过}{滤}理
没有用啊,ip地址也没问题{:1_907:} stitch007 发表于 2022-7-22 11:03
require('https').globalAgent.options.ca = require('ssl-root-cas/latest').create();
加上这段代码试一 ...
这样?
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))
输出:
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 (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')"
exited with code=0 in 2.891 seconds
照提示换了
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))
输出
node "e:\code\test.js"
unable to verify the first certificate
exited with code=0 in 0.408 seconds nicholasdeng 发表于 2022-7-22 11:01
会不会是后台或者服务器的问题呢
细说,大家都有流量{:301_986:}
页:
[1]
2