Laravel返回text/html而不是json



我在响应标头中有这个:

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"

我的控制器非常简单:

public function login(Request $request){
      return response()->json([
        'name' => 'Abigail',
        'state' => 'CA'
        ]);
    }

我使用角度进行发布。

> Laravel使用Response class提供修改标头信息。

在控制器中尝试这种方式:

$contents = View::make('embedded')->with('foo', $foo);
$response = Response::make($contents, $statusCode);
$response->header('Content-Type', 'text/plain');
return $response;
我知道

这是一个老问题,但我找到了一个简单的解决方案......这是:

return response($html, 200)->header('Content-Type', 'text/html')

最新更新