Nodejs request to a web service with .p12 certificate

前端 未结 1 1665
伪装坚强ぢ
伪装坚强ぢ 2021-01-13 11:30

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

相关标签:
1条回答
  • 2021-01-13 12:17

    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

    0 讨论(0)
提交回复
热议问题