[英]How download file from github.com whith NodeJs (https)
I'm trying to download a 7zip file from Github without success, with the following code: 我正在尝试从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);
});
this code don't download the file from Github, but if I change options to download Notepad++ with: 此代码不会从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
};
The script downloads the file without error, I test downloading from Github with wget: 脚本下载文件没有错误,我测试了如何使用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
And the download occurs without errors. 并且下载发生没有错误。
how can I solve this issue? 我该如何解决这个问题?
ps.: I'm sorry for my terrible english. ps:对不起,我的英语不好。
In your options, you use the following 在选项中,使用以下内容
rejectUnauthorized : false, //this says reject unauthorised user
requestCert : true, //this says request a certificate. You don't provide one.
Can you try 你能试一下吗
rejectUnauthorized : true,
requestCert : false
I found a solution: this issue occurs because the URL has a redirect, a simple solution is install a module called follow-redirects and change: 我找到了一个解决方案:发生此问题是因为URL具有重定向,一个简单的解决方案是安装一个名为follow-redirects的模块并进行更改:
var https = require('https');
to 至
var https = require('follow-redirects').https;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.