【问题标题】:return $res->withStatus(401) in SlimFramework3 not appearing to work?在 SlimFramework3 中返回 $res->withStatus(401) 似乎不起作用?
【发布时间】:2016-03-31 09:57:10
【问题描述】:

所以我已经进行了相当多的挖掘,似乎只能提出关于 SlimFramework 2 的信息,而关于 3 的信息则不多。

我的问题是这样的:

return $res->withStatus(401)->withHeader('Content-type','application/json')->write(json_encode(array(
            'Error'=>'Your session has timed out.',
            'X-SessionToken' => $session_uuid,
            'Server date/time' => date('c'),
            'Last activity' => Session::sharedInstance()->last_activity(),
            'Path' => $path
        )));

仍然返回状态 200,内容类型仍然设置为 text/html,但我的所有身体都在那里。有什么想法吗?我尝试查看有关 write() 的 PSR-7 文档,以查看是否可能在此之后将标头和状态设置回默认值,但没有看到任何内容。

Browser screen shot.

【问题讨论】:

    标签: php slim slim-3


    【解决方案1】:

    所以在进行了更多的查看和调试之后,我发现它没有设置标题,因为它只在 !headers_sent() 时设置它们,它返回为 false。这意味着我在某处有额外的输出。结果在我的 PHP 文件的最底部,我的所有代码都在我关闭后有一个额外的行?>。如此业余的错误。

    【讨论】:

      猜你喜欢
      • 2011-11-18
      • 2011-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多