I'm trying to download a pdf file from a link using the following code. However, I got 404 error page. The same link just work fine in browser. What would be the cause?
var http = require('http');
var options = {
host: 'www.xxxx.xxx',
path: '/achieved/a1.pdf'
};
callback = function(response) {
var str = '';
//another chunk of data has been recieved, so append it to `str`
response.on('data', function (chunk) {
str += chunk;
});
//the whole response has been recieved, so we just print it out here
response.on('end', function () {
console.log(str);
});
}
http.request(options, callback).end();