我有一个 Laravel GET 端点,它应该返回应用程序 json,但仍然返回 text/html。我如何让它返回“application/json”?
端点返回:
return response(['status' => 'success'], 200, ['Content-Type => application/json']);
我做错了什么吗?还是内容编码有问题?
我现在想通了。问题是与邮递员的通话。我用标头
Accept: */*
调用端点。解决方案是简单地请求正确的响应类型 (application/json),或者按照此处所述覆盖中间件中的 api 请求,因为 Laravel 返回 html 格式的响应 - 对于 json。