使用 https.request 忽略 node.js 中无效的自签名 ssl 证书? [英] Ignore invalid self-signed ssl certificate in node.js with https.request?

查看:50
本文介绍了使用 https.request 忽略 node.js 中无效的自签名 ssl 证书?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个可以登录到我的本地无线路由器 (Linksys) 的小应用程序,但我遇到了路由器自签名 ssl 证书的问题.

I'm working on a little app that logs into my local wireless router (Linksys) but I'm running into a problem with the router's self-signed ssl certificate.

我运行 wget 192.168.1.1 并得到:

I ran wget 192.168.1.1 and get:

ERROR: cannot verify 192.168.1.1's certificate, issued by `/C=US/ST=California/L=Irvine/O=Cisco-Linksys, LLC/OU=Division/CN=Linksys/emailAddress=support@linksys.com':
Self-signed certificate encountered.
ERROR: certificate common name `Linksys' doesn't match requested host name `192.168.1.1'.
To connect to 192.168.1.1 insecurely, use `--no-check-certificate'.

在节点中,被捕获的错误是:

In node, the error being caught is:

{ [Error: socket hang up] code: 'ECONNRESET' }

我当前的示例代码是:

var req = https.request({ 
    host: '192.168.1.1', 
    port: 443,
    path: '/',
    method: 'GET'

}, function(res){

    var body = [];
    res.on('data', function(data){
        body.push(data);
    });

    res.on('end', function(){
        console.log( body.join('') );
    });

});
req.end();

req.on('error', function(err){
    console.log(err);
});

我怎样才能让 node.js 做相当于--no-check-certificate"的事情?

How can I go about getting node.js to do the equivalent of "--no-check-certificate"?

推荐答案

廉价且不安全的答案:

添加

process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;

在代码中,在调用 https.request()

在此问题

这篇关于使用 https.request 忽略 node.js 中无效的自签名 ssl 证书?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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