Skip to content

HTTPS request works using the https module but not in Axios #662

@jamesw201

Description

@jamesw201

This request works with the https library:

const options = {
    hostname: 'baseurl.com',
    path: '/accounts',
    method: 'GET',
    ca: fs.readFileSync(`${path}CA.pem`),
    cert: fs.readFileSync(`${path}CERT.pem`),
    key: fs.readFileSync(`${path}KEY.pem`),
    auth: 'user:password',
    rejectUnauthorized: false
};
const req = https.request(options, (res) => {
    res.on('data', (data) => {
        process.stdout.write(data);
    });
});
req.end();
req.on('error', (e) => {
    console.error(e);
});

but this seemingly equivalent request does not work using Axios:

const instance = axios.create({
    baseURL: 'https://baseurl.com',
    httpsAgent: new https.Agent({
        ca: fs.readFileSync(`${path}CA.pem`),
        cert: fs.readFileSync(`${path}CERT.pem`),
        key: fs.readFileSync(`${path}KEY.pem`),
        auth: 'user:password',
        rejectUnauthorized: false
    })
});

instance.get('/accounts')
  .then(_ => console.log(`response: ${_}`))
  .catch(err => console.log(`error: ${err.stack}`));

Instead it throws this error:
error: Error: write EPROTO
at Object.exports._errnoException (util.js:870:11)
at exports._exceptionWithHostPort (util.js:893:20)
at WriteWrap.afterWrite (net.js:763:14)

I've tried these variations of base url but no luck:

any help much appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions