1

I have written a API which returns Certificate file in response. and this certificate file i am using in another API for authentication, this API returns header too long error when certificate is passed in headers request.

Code which returns certificate file.

router.get('/certificate', function (req, res, next) {
  try {
    let certFile, filename; 
    filename = "Cert.pfx";
    certFile = fs.readFileSync(filename, 'utf-8');

    res
      .status(200)
      .send(certFile);
  }
  catch (err) {
    res
      .status(500)
      .send('Error occured : ' + err);
  }
});

Code where i am reading certificate file.

 request
        .get('BASE_URL/certificate')
        .on('response', function (response) { 
            console.log(response.body);


            let promise = new Promise((resolve, reject) => {
            request.get(
                {
                    url: serviceUrl,
                    pfx: response.body,
                    passphrase: password,
                    headers:
                    {
                        'Content-Type': 'text/xml'
                    },
                    body: xmlBody
                },
                (error, response, body) => {
                    if (error) {
                        console.log("ERROR occured :" + error);
                        reject('Error in calling business service');
                    }
                    else {

                        console.log(body);
                        console.log(response.statusCode);
                    }
                });


        }).on('error', function (err) {
            console.log(err)
        })

Please help me on this

Rehan
  • 69
  • 7

0 Answers0