首页 > 解决方案 > 在 Slim 框架中使用 JSON 流响应

问题描述

我需要以某种方式从我的 API 做出响应->withHeader('Transfer-Encoding', 'chunked'),但据我所知,它需要响应正文中的流。如何将我的键值数组转换为 JSON 流并做出响应?

现在,我的代码如下所示:

        return $response->withHeader('Connection', 'close')
                ->withHeader('Pragma', 'no-cache')
                ->withHeader('Content-type', 'application/json;charset=utf8')
                ->withHeader('Access-Control-Allow-Origin', '*')
                ->withoutHeader('Content-Length')
                ->withHeader('Transfer-Encoding', 'chunked')
                ->withStatus(200)
                ->withJson($resp);

$resp我的数组在哪里。但它不会工作...

标签: phpjsonstreamslim

解决方案


推荐阅读