Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 如何使用NodeJs(https)从github.com下载文件_Node.js_Github_Https_Download - Fatal编程技术网

Node.js 如何使用NodeJs(https)从github.com下载文件

Node.js 如何使用NodeJs(https)从github.com下载文件,node.js,github,https,download,Node.js,Github,Https,Download,我试图从Github下载一个7zip文件,但没有成功,代码如下: var fs = require('fs'); var https = require('https'); options = { host : "github.com", port : 443, path : "/msysgit/msysgit/releases/download/Git-1.9.5-previ

我试图从Github下载一个7zip文件,但没有成功,代码如下:

var fs    = require('fs');
var https = require('https');

options = { 
    host               : "github.com", 
    port               : 443,
    path               : "/msysgit/msysgit/releases/download/Git-1.9.5-preview20150319/PortableGit-1.9.5-preview20150319.7z",
    method             : 'GET',
    rejectUnauthorized : false,
    requestCert        : true,
    agent              : false
};

var file = fs.createWriteStream("installer.7z");

var request = https.get(options, function(response){
    response.pipe(file);


    file.on("finish", function(){
        file.close();
    });
});

request.end();

request.on('error', function(err){
    throw (err);
});
此代码不会从Github下载该文件,但如果我更改了下载Notepad++的选项,请执行以下操作:

options = { 
    host               : "notepad-plus-plus.org", 
    port               : 443,
    path               : "/repository/6.x/6.8/npp.6.8.bin.7z",
    method             : 'GET',
    rejectUnauthorized : false,
    requestCert        : true,
    agent              : false
};
脚本无错误地下载文件,我使用wget从Github测试下载:

wget --no-check-certificate --output-document="installer.7z" https://github.com/msysgit/msysgit/releases/download/Git-1.9.5-preview20150319/PortableGit-1.9.5-preview20150319.7z
下载时不会出现错误

我如何解决这个问题


注:我为我糟糕的英语感到抱歉。

在您的选项中,您可以使用以下选项

rejectUnauthorized : false, //this says reject unauthorised user
requestCert        : true, //this says request a certificate. You don't provide one.
你能试试吗

rejectUnauthorized : true,
requestCert        : false

在您的选项中,您可以使用以下选项

rejectUnauthorized : false, //this says reject unauthorised user
requestCert        : true, //this says request a certificate. You don't provide one.
你能试试吗

rejectUnauthorized : true,
requestCert        : false
我找到了一个解决方案: 出现此问题是因为URL具有重定向,一个简单的解决方案是安装名为“跟随重定向”的模块并更改:

var https = require('https');

我找到了一个解决方案: 出现此问题是因为URL具有重定向,一个简单的解决方案是安装名为“跟随重定向”的模块并更改:

var https = require('https');