0

我正在使用 codeigniter 4 在文档中它说要使用该setHeader功能(来自控制器内)

例如:

$this->response->setHeader('Content-Type', "application/pdf");

在上面的示例中,'Content-Type': 'text/html' 当我查看 chrome 开发工具中的响应时,我仍然会得到。

但是,如果我使用该header()功能,即:

header("Content-Type: application/pdf");

我得到了预期的结果。

为什么是这样?

4

2 回答 2

0

您必须链接发送方法。没有发送方法,它不会改变标题。

以下是关于如何使用它的片段。

$this->response->setContentType('application/json')->send();
于 2021-01-28T06:38:23.973 回答
0

试试 $this->response->setContentType("application/pdf"); 我认为这就是它在 codeigniter 中改变内容类型的原因。

于 2021-01-27T04:01:59.630 回答