php - 在 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
我的数组在哪里。但它不会工作...
解决方案
推荐阅读
- javascript - RxJS:仅用于存储和通知最新消息的主题
- python - 如何检查消息作者的角色 + 如何在 Discord.py 上 DM 特定角色?
- c - 如何在C中按字母数字顺序对文件名进行排序
- excel - 将小数添加到变量“vSum”时出现类型不匹配错误
- spring-cloud - Spring Cloud 禁用功能区不适用于 Netflix Zuul 依赖项
- javascript - 当 promise 在 promise.allSettled 中解决时,控制台记录成功消息
- python - 如何对具有相同 key:value 的 mongo 文档进行分组并以数组的形式返回响应?
- python - 无法将 tkinter 中的按钮放置在所需区域
- c# - 使用 nunit C# 上传文件的单元测试用例
- c# - 使用 ActionResult 时在中间件中设置响应头