我在响应 header 中有这个:
Response headers (165 B)
Host
"localhost:8000"
[Learn More]
Connection
"close"
[Learn More]
Content-Type
"text/html; charset=UTF-8"
[Learn More]
Date
"Thu, 16 Mar 2017 14:33:53 GMT"
[Learn More]
Transfer-Encoding
"chunked"
我的 Controller 非常简单:
public function login(Request $request){
return response()->json([
'name' => 'Abigail',
'state' => 'CA'
]);
}
我使用 angular 进行发布。
最佳答案
Laravel 使用 Response 类提供修改头部信息。
在你的 Controller 中尝试这种方式:
$contents = View::make('embedded')->with('foo', $foo);
$response = Response::make($contents, $statusCode);
$response->header('Content-Type', 'text/plain');
return $response;
关于Laravel 返回文本/html 而不是 json?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42837126/