我有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。
有没有人能帮我一下?我会非常感谢你的。
发布于 2020-10-27 14:01:22
我找到了解决方案。这是由resitify代码引起的:
https://github.com/restify/node-restify/blob/master/lib/response.js#L477
只需使用res.sendRaw(200, response)即可
https://stackoverflow.com/questions/64530890
复制相似问题