Created
December 5, 2022 07:57
-
-
Save wuriyanto48/0029d3e2f5ed8b1bfc6e96ffbe609af4 to your computer and use it in GitHub Desktop.
axios custom httpAgent with root certificate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const https = require('https'); | |
const axios = require('axios'); | |
const fs = require('fs'); | |
const httpsAgent = new https.Agent({ | |
requestCert: true, | |
rejectUnauthorized: true, | |
ca: [fs.readFileSync('./root_cert.pem')], | |
// cert: [fs.readFileSync('./cert.pem')] | |
}); | |
const getData = async () => { | |
try { | |
const data = await axios({ | |
url: 'https://api-cool.com/v1/people', | |
method: 'get', | |
auth: { | |
username: 'user', | |
password: '695849d' | |
}, | |
httpsAgent: httpsAgent | |
}); | |
console.log(data); | |
} catch(e) { | |
console.log('error...'); | |
console.log(e); | |
} | |
} | |
getData(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-----BEGIN CERTIFICATE----- | |
long certificate | |
-----END CERTIFICATE----- | |
-----BEGIN CERTIFICATE----- | |
short root cert | |
-----END CERTIFICATE----- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment