通过NodeJS调用远程API,并将结果附加到我的API失败

我正在尝试从CA API调用一个API,该API以格式p7b的附件forms返回证书文件。 我需要附加到我的API并返回到我的客户端。 我是NodeJS的新手,我无法得到这个工作。 有人可以帮忙吗?

我试过res.pipe(),它没有工作。 我在下面给出了我的代码片断。

app.get("/api/certificate/:certificateid", function (req, res) { var certificateId = req.params.certificateid; var header = { "X-DC-DEVKEY": apiKey, "Content-Type": "application/json" }; var options = { host: certUrl, port: 443, method: 'GET', path: 'xxxxx/certificate/' + certificateId + '/download/format/p7b', headers: header }; https.request(options, function (res1) { // res1.setEncoding('gzip'); DID NOT WORK res1.on('data', function (data) { var result = JSON.stringify(data); console.log(result); res.setHeader('Content-type', 'application/x-pkcs7-certificates'); res.setHeader('Content-Encoding', 'gzip'); res.setHeader('Content-Disposition', 'filename=blockwaveinsurance_com.p7b'); res.end(data,'gzip'); }); }).end(); }); 

出于某种原因,https不工作,我通过pipe道或任何其他方式重新从远程API的附件到我的API,但我能够通过请求模块做到这一点。 这是代码,如果有人需要它

 var certUrl='www.xxxx.com'; var apiKey='xxxxx'; app.get("/api/certificate/:certificateid", function (req, res) { var certificateId = req.params.certificateid; var url=certUrl+"/services/v2/certificate/" + certificateId + "/download/format/p7b"; var options = { url: url, headers: { "X-DC-DEVKEY": apiKey, } }; function callback(error, response, body) { if (!error && response.statusCode == 200) { console.log('no error'); } } request(options, callback).pipe(res); });