Laravel 返回错误的内容类型

问题描述 投票:0回答:1

我有一个 Laravel GET 端点,它应该返回应用程序 json,但仍然返回 text/html。我如何让它返回“application/json”?

端点返回:

return response(['status' => 'success'], 200, ['Content-Type => application/json']);

邮递员回复: enter image description here

我做错了什么吗?还是内容编码有问题?

json laravel http response
1个回答
0
投票

我现在想通了。问题是与邮递员的通话。我用标头

Accept: */*
调用端点。解决方案是简单地请求正确的响应类型 (application/json),或者按照此处所述覆盖中间件中的 api 请求,因为 Laravel 返回 html 格式的响应 - 对于 json。

laravel - 邮递员返回 HTML 而不是 JSON?

© www.soinside.com 2019 - 2024. All rights reserved.