乐奇 Rokid 开放社区 node superagent ssl证书验证问题 报错unable to verify the first certificate

node superagent ssl证书验证问题 报错unable to verify the first certificate

node使用superagent库,请求时报错unable to verify the first certificate
表示客户端无法验证 服务器提供的SSL证书链中的第一个证书

解决方法
在代码中直接加入

//禁用SSL证书验证
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
  • 1.
  • 2.

// 或者直接在代理请求时设置
https.globalAgent.options.rejectUnauthorized = false;
  • 1.
  • 2.

然后再进行请求即可解决


如问题无法解决

使用superagent关闭ssl验证报错

Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment varia

ble to ‘0’ makes TLS connections and HTTPS requests insecure by disabling certif

icate verification.


则可引入https禁止ssl验证

const superagent = require('superagent');
const https = require('https');
 
// 创建一个新的Agent,关闭rejectUnauthorized选项来禁用SSL验证
const agent = new https.Agent({
  rejectUnauthorized: false
});
 
// 使用superagent并指定agent
superagent
  .get('url')
  .agent(agent)
  .end((err, res) => {
    if (err) {
      console.error(err);
      return;
    }
    console.log(res.text);
  });
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
原创作者: u_14649375 转载于: https://blog.51cto.com/u_14649375/11578349

更多推荐

  • 浏览量 482
  • 收藏 0
  • 0

所有评论(0)

查看更多评论 
已为社区贡献1条内容