错误:无法验证Node.js中的第一个证书 [英] Error: unable to verify the first certificate in nodejs

查看:505
本文介绍了错误:无法验证Node.js中的第一个证书的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用URL从jira服务器下载文件,但出现错误. 如何在代码中包含证书以进行验证 错误:

I'm trying to download a file from jira server using an url but I'm getting an error. how to include certificate in the code to verify Error:

Error: unable to verify the first certificate in nodejs

at Error (native)
    at TLSSocket.<anonymous> (_tls_wrap.js:929:36)

  at TLSSocket.emit (events.js:104:17)

at TLSSocket._finishInit (_tls_wrap.js:460:8)

我的Nodejs代码:

var https = require("https");
var fs = require('fs');
var options = {
    host: 'jira.example.com',
    path: '/secure/attachment/206906/update.xlsx'
};

https.get(options, function (http_res) {

    var data = "";


    http_res.on("data", function (chunk) {

        data += chunk;
    });


    http_res.on("end", function () {

        var file = fs.createWriteStream("file.xlsx");
        data.pipe(file);

    });
});

推荐答案

尝试添加适当的根证书

与盲目接受未经授权的端点相比,这始终是一个更安全的选择,后者只能作为最后的手段.

Try adding the appropriate root certificate

This is always going to be a much safer option than just blindly accepting unauthorised end points, which should in turn only be used as a last resort.

这可以像添加

require('https').globalAgent.options.ca = require('ssl-root-cas/latest').create();

到您的应用程序.

SSL根CA的npm软件包(此处使用)有关此问题的有用软件包.

The SSL Root CAs npm package (as used here) is a very useful package regarding this problem.

这篇关于错误:无法验证Node.js中的第一个证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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