【发布时间】:2015-10-15 10:02:21
【问题描述】:
我正在尝试从 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
并且下载没有错误。
我该如何解决这个问题?
ps.:对不起,我的英语很糟糕。
【问题讨论】:
标签: node.js github https download