I'm trying to request the html of a website using request but I keep getting an access denied error. How do I get past this? Here is the code for the function below:
const request = require('request');
function firstShoe() {
request('https://www.jdsports.co.uk/product/green-nike-vapormax/281735/', function (error, response, body) {
console.log('body:', body);
});
}
Error:
</BODY>
</HTML>
body: <HTML><HEAD>
<TITLE>Access Denied</TITLE>
</HEAD><BODY>
<H1>Access Denied</H1>
You don't have permission to access "http://www.jdsports.co.uk/product/green-nike-vapormax/281735/" on this server.<P>
Reference #18.609d3e17.1500116386.15f0cb85
</BODY>
</HTML>
Found a solution by passing the user-agent into the headers.
function firstShoe() {
var options = {
headers: {'user-agent': 'node.js'}
}
request('https://www.jdsports.co.uk/product/green-nike-vapormax/281735/', options, function (error, response, body) {
console.log(body);
message.channel.send(body);
});
}