我正在尝试使用got下载https://www.stackoverflow.com
或https://www.google.com
,而我在代理服务器后面
如果不使用rejectUnauthorized: false
,我会一直遇到这个错误RequestError: unable to get local issue
。我知道这个rejectUnauthorized: false
解决方案是一个安全问题。stackoverflow.com
和google.com
必须具有可信的知名CA,那么为什么我会收到此错误?
import got from "got";
import { HttpsProxyAgent } from "hpagent";
const result = await got("https://www.google.com", {
agent: {
https: new HttpsProxyAgent({
proxy: process.env.https_proxy,
rejectUnauthorized: false, // If true => RequestError: unable to get local issuer certificate
}),
},
}).text();
console.log("result:", result);
字符串
另一方面,对https://jsonplaceholder.typicode.com
的请求不需要设置rejectUnauthorized: false
即可工作
const result = await got("https://jsonplaceholder.typicode.com", {
agent: {
https: new HttpsProxyAgent({
proxy: process.env.https_proxy,
}),
},
}).text();
型
你能解释一下这种不一致性以及如何解决它吗?
- 注意:我使用的是Node.js 14.17.6*
1条答案
按热度按时间izkcnapc1#
再试一次,也许现在已经修复了,我正在使用这个库传递证书选项,似乎对我很好。