Hey guys I'm struggling a little bit with Node JS and HTTPS requests. The following code actually works fine but I don't know how to set custom request headers like X-Forwarded-For and User Agent. Is there a way to add these?
Thanks :)
Here is my code:
const https = require('https');
const options = {
hostname: 'offertoro.com',
port: 443,
path: '/',
method: 'GET'
};
const req = https.request(options, (res) => {
console.log('statusCode:', res.statusCode);
console.log('headers:', res.headers);
res.on('data', (d) => {
process.stdout.write(d);
});
});
req.on('error', (e) => {
console.error(e);
});
req.end();
options argument accepts a headers property.
const options = {
hostname: 'offertoro.com',
port: 443,
path: '/',
method: 'GET',
headers: {
'X-Forwarded-For': 'xxx',
'User-Agent': 'Foo'
}
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With