流明 5.7 JSON 响应极限

Lumen 5.7 JSON response limit

我的数据库中存储了一大段文本,可以成功地从我的 DBdd() 中提取它,log::debug() 内容也没有问题。文本可以在这里看到:https://pastebin.com/KQNYW623

当我尝试 return 文本的 JSON 响应时,问题就来了。在 api.php 路由文件中安装干净的 Lumen 5.7 我有这条路由:

$router->get('/', function () use ($router) { return json_encode("*insert large content here*"); //this is where the big text goes, I won't paste it fully here but it's here in my code as a string });

如果我访问这条路线,我得到一个空白页面。在我的屏幕、Postman 或 curl 中绝对没有任何显示。错误日志中没有错误,什么都没有。只是空白。

如果我放置比大文本小得多的任何其他内容(如 hello world),我可以毫无问题地输出响应。有人可以阐明这个问题的根本原因是什么吗? Lumen/Laravel 中的回复是否有字符限制?

---更新---

所以如果我这样做 echo response()->json($string)(其中 $string 是一个保存长文本的变量)我可以看到字符串已被编码为 JSON 并且响应 headers 已添加,所有这些都在屏幕上输出。但是,return response()->json($string) 仍然会继续 return 空白响应。

有人知道为什么 return 没有从 response() 发回数据吗?

要 return 一个 json 流明响应 laravel,我想你可以看看:

https://lumen.laravel.com/docs/5.7/responses

The json method will automatically set the Content-Type header to application/json, as well as convert the given array to JSON using the json_encode

此外,如果您有一个与数据库关联的模型,您可以自动将 json 转换为数组,请参阅:

if your database has a JSON or TEXT field type that contains serialized JSON, adding the array cast to that attribute will automatically deserialize the attribute to a PHP array

https://laravel.com/docs/5.7/eloquent-mutators#array-and-json-casting

修复了问题:我从这里获取的 CORS 中间件 class:enter link description here

Content-Length > 6K 的响应被操纵为长度为 0,但仍然 return 为 200 响应。感谢大家的帮助和建议。