我有一个GET Http请求,如下所示
const getData = async (req: Request, res: Response): Promise<void> => {
try {
.... some code...
const response = await createPdfResponse(location);
res.setHeader("Accept", "application/pdf");
res.setHeader("Content-Type", "application/pdf");
res.setHeader(
"Content-Disposition",
"inline; filename=fileName.pdf"
);
res.send(200, response);
} catch (error) {
const errorBody = error.body;
const statusCode = error.code;
res.send(statusCode, { errorBody });
}
};
当我得到响应时,它带有Content-Type:application / octet-stream。
我需要Content-Type:application / pdf。
有人可以帮我吗?我将非常感谢您。
答案 0 :(得分:0)
我找到了解决方案。这是由于重新设置代码引起的:
https://github.com/restify/node-restify/blob/master/lib/response.js#L477
只需使用res.sendRaw(200, response)