2017-03-16 127 views
0

我有这样的响应头:Laravel返回文本/ 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' 
     ]); 
    } 

林采用了棱角分明的岗位。

+0

当前是什么反应? –

+0


已弃用:自动填充$ HTTP_RAW_POST_DATA已弃用,将在未来的版本中删除。为避免此警告,在php.ini中将'always_populate_raw_post_data'设置为'-1',并改为使用php://输入流。在未知在线

警告:无法修改标题信息 - 在未知已经发出已上线头
{ “名”: “阿比盖尔”, “状态”:” CA“} – uzhas

+0

它返回我这样..我不知道它是否错误,因为角度发布或? – uzhas

回答

3

Laravel提供了修改使用响应类的头信息。

试试这个办法在你的控制器:

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

Laravel默认返回JSON的,如果你不返回视图...你试过

return ['name' => 'Abigail', 'state' => 'CA']; 
+0

同样的问题......也许它是因为angular post,因为我进入当前响应:
已弃用:自动填充$ HTTP_RAW_POST_DATA已弃用,将在未来的版本中删除。为避免此警告,在php.ini中将'always_populate_raw_post_data'设置为'-1',并改为使用php://输入流。在未知在线

警告:无法修改标题信息 - 在未知已经发出已上线头
{ “名”: “阿比盖尔”, “状态”:” CA“} – uzhas

相关问题