So, the title is pretty straightforward. I want to consume a web service from a company and I got .cer and .p12 files. Supposedly, I should use .p12 when making a request. I
Use pfx
property in agentOptions for pkcs12 format :
'use strict';
const request = require('request');
const fs = require('fs');
var options = {
url: 'https://some-url/api',
headers: {
"content-type": "application/json",
},
agentOptions: {
pfx: fs.readFileSync(__dirname + '/certs/myCert.p12'),
passphrase: ''
}
};
request.get(options, (error, response, body) => {
console.log(error);
console.log(response);
console.log(body);
});
If your certificate is self signed, check this