Node.js请求CERT_HAS_EXPIRED [英] Node.js request CERT_HAS_EXPIRED
问题描述
我正在使用Mikeal的请求( https://github.com/mikeal/request )发出https请求一个服务器但是,我不断收到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?
推荐答案
将此添加到文件的顶部:
Add this at the top of your file:
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
危险这将禁用整个节点的HTTPS / SSL / TLS检查。 js环境。请参阅下面的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屋!