繁体   English   中英

内容类型:应用程序/pdf 更改为内容类型:应用程序/八位字节流

[英]Content-Type: application/pdf changing to Content-Type: application/octet-stream

我有一个 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。

我需要内容类型:应用程序/pdf。

有人可以帮我解决这个问题吗? 我会非常感谢你。

我找到了解决方案。 这是由重新定位代码引起的:

https://github.com/restify/node-restify/blob/master/lib/response.js#L477

只需使用res.sendRaw(200, response)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM