如何解析证书链中的自签名证书

时间:2019-11-25 13:50:14

标签: javascript node.js api ibm-cloud self-signed

运行以下node.js代码(使用IBM Cloud Function或任何其他IDE)时遇到问题。我正在尝试调用外部API,但错误是:

  

证书链中的自签名证书

我尝试将请求标头设置为

  

rejectedUnauthorized:否

使用此标头,错误消失了,但是HTTPS响应为空

我正在使用的代码是:

function main(params) {


let data = params.mxUser;
let buff = new Buffer(data);
let base64data = buff.toString('base64');

const options = {
   method: 'GET',
   rejectUnauthorized: false,
   headers: {
       'AUTHORIZATION': base64data
   }
 };

var url = 'myAPI'

return new Promise((resolve, reject) => {
    const https = require('https');
    console.log(url)
    https.get(url, options, (resp) => {
        let data = '';

        // A chunk of data has been recieved.
        resp.on('data', (chunk) => {
            data += chunk;
            console.log(data)
        });

        // The whole response has been received. Print out the result.
        resp.on('end', () => {
            //explanation = JSON.parse(data);


            console.log(data)
            //resolve({ Response : explanation })
            resolve({ Response : data })

        });

    }).on("error", (err) => {
        console.log("Error: " + err.message);
        reject({ error: err.message })
    });

})

}

谢谢

0 个答案:

没有答案