相关疑难解决方法(0)

使用https.request忽略node.js中无效的自签名ssl证书?

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

我运行wget 192.168.1.1并得到:

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'.
Run Code Online (Sandbox Code Playgroud)

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

{ [Error: socket hang up] code: 'ECONNRESET' }
Run Code Online (Sandbox Code Playgroud)

我目前的示例代码是:

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);
});
Run Code Online (Sandbox Code Playgroud)

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

https ssl-certificate node.js

279
推荐指数
7
解决办法
29万
查看次数

如何在 XmlHttpRequest 中忽略自签名证书

我正在开发一个用 javascript 编写的项目。我可以看到,对于请求,已经创建了 XMLHttpRequest 对象。

它对“http”请求工作正常,但对“https”请求失败。由于我在开发环境中调试它,我只想知道如何忽略XmlHttpRequest对象中的自签名证书?

在搜索时我发现了这个

httpreq = new ActiveXObject("Msxml2.ServerXMLHTTP.3.0");
httpreq.setOption(2, 13056);
Run Code Online (Sandbox Code Playgroud)

但答案不适用于现代浏览器,如 Microsoft edge、chorme...

我也发现了这个,它清楚地表明 setOption() 可用于忽略 ssl 证书。

我在代码中可以看到的一个区别是我使用以下命令创建了 httpreq:

httpreq = new xmlhttprequest();//This is for chorme and Firefox
Run Code Online (Sandbox Code Playgroud)

那么有什么方法可以忽略 XmlHttpRequest 中的自签名证书吗?

javascript https xmlhttprequest ssl-certificate typescript

8
推荐指数
1
解决办法
4686
查看次数