我使用以下代码从函数返回Json编码的响应。
return response()->json($returnArray);
然而,响应如下,并包含HTTP标头:
Cache-Control: no-cache, private
Content-Type: application/json
Date: Mon, 23 Oct 2017 15:34:59 GMT
{"status":"success"}
如何设置响应,以便不包含标题,只包含JSON?
{"status":"success"}
答案 0 :(得分:0)
怎么样:
return response()->toJson([
'status' => 'success',
], 201);
或:
return Response::json(['data' => $array],201);
答案 1 :(得分:0)
我遇到了一些问题。
在我的情况下,问题出在方法中的string
返回类型提示中。
示例:强>
public function getJson(): string{
return response()->json(['foo' => 'bar']);
}
所以,我将string
替换为JsonResponse
并解决了所有问题。
也许会帮助别人。