I'm trying to send a GET request to a user/pass protected API. I'm using Javascript and adding in an "auth" option.
const https = require('https');
const headers= {
'Accepts' : 'application/json',
}
const options = {
hostname: 'api.com/more/info',
port: 443,
path: '/',
auth: 'username:password',
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();
The error I receive when this code is run is:
Error: getaddrinfo ENOTFOUND api/com/more/info
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:66:26) {
errno: -3008,
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'api.com/more/info'
}
The hostname has been changed for anonymity.
What am I doing wrong?
Thanks in advance for any advice.
1 Answer 1
'api.com/more/info' is probably not your hostname.
Try with these options instead:
const options = {
hostname: 'api.com',
port: 443,
path: '/more/info',
auth: 'username:password',
method: 'GET'
};
answered May 9, 2020 at 17:28
Bertrand Marron
22.3k8 gold badges63 silver badges95 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-js
api.com/more/info.