Node.js 请求 CERT_HAS_EXPIRED [英] Node.js request CERT_HAS_EXPIRED

查看:46
本文介绍了Node.js 请求 CERT_HAS_EXPIRED的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Mikeal 的请求 (https://github.com/mikeal/request) 向服务器.但是,我不断收到 CERT_HAS_EXPIRED 的授权错误.

I'm using Mikeal's request (https://github.com/mikeal/request) to make an https request to a server. However, I keep getting an authorization error of CERT_HAS_EXPIRED.

request({
        url: 'https://www.domain.com/api/endpoint',
        strictSSL: false
    }, function(error, response, body) {
        if(!error && response.statusCode == 200) {
            res.json(JSON.parse(body));
        } else {
           res.json(response.statusCode, {'error': 'error'})
        }
});

我尝试将strictSSL 设置为true 和false,两者都输出相同的CERT_HAS_EXPIRED 错误.是什么导致了这个问题,有没有办法在 nodejs 中修复它?

I've tried setting strictSSL to true and false, both output same error of CERT_HAS_EXPIRED. What is causing this issue and is there any way to fix it in nodejs?

推荐答案

在文件顶部添加:

process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';

危险 这会在整个 node.js 环境中禁用 HTTPS/SSL/TLS 检查.请参阅下面使用 https 代理的解决方案.

DANGEROUS This disables HTTPS / SSL / TLS checking across your entire node.js environment. Please see the solution using an https agent below.

这篇关于Node.js 请求 CERT_HAS_EXPIRED的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆