NodeJS 如何在代理背后使用https下载资源,而不使用“rejectUnauthorized:false”?

uajslkp6  于 11个月前  发布在  Node.js
关注(0)|答案(1)|浏览(95)

我正在尝试使用got下载https://www.stackoverflow.comhttps://www.google.com,而我在代理服务器后面
如果不使用rejectUnauthorized: false,我会一直遇到这个错误RequestError: unable to get local issue。我知道这个rejectUnauthorized: false解决方案是一个安全问题。
stackoverflow.comgoogle.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*
izkcnapc

izkcnapc1#

再试一次,也许现在已经修复了,我正在使用这个库传递证书选项,似乎对我很好。

相关问题