在'wget-improved'
上尝试node.js
模块时,我会在错误函数上获得Server responded with unhandled status: 400
这里是fileToDownload,fileUrl是'public / assets /
var wget = require('wget-improved');
var options = {
protocol: 'http',
headers :{'User-Agent': 'Node'},
method: 'GET'
};
var download = wget.download(fileToDownload, fileUrl, options);
download.on('error', function(err) {
console.log("error download");
console.log(err);
var data = {
"CODE": 0,
"error": "error download"
}
return;
});
download.on('start', function(fileSize) {
console.log("file downloaded ")
console.log(fileSize);
});
download.on('end', function(output) {
console.log(output);
var data = {
"CODE": 1
};
return;
});
download.on('progress', function(progress) {
// code to show progress bar
});`