Skip to content

Instantly share code, notes, and snippets.

@Tlaloc-Es
Created June 25, 2018 11:58
Show Gist options
  • Save Tlaloc-Es/740c5e857d2c91c86836ea13ff30ed50 to your computer and use it in GitHub Desktop.
Save Tlaloc-Es/740c5e857d2c91c86836ea13ff30ed50 to your computer and use it in GitHub Desktop.
Download file in node with basic auth and User-Agent.js
var https = require('https');
var fs = require('fs');
var options = {'host': 'localhost',
'path':'/path/to/file',
'auth': 'user:password',
'headers':{'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0'}
};
var file = fs.createWriteStream("file.zip");
var request = https.request(options, function (response) {
console.log('STATUS: ' + response.statusCode);
console.log('HEADERS: ' + JSON.stringify(response.headers));
response.pipe(file)
});
request.end();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment