Laravel 4始终返回HTTP状态代码200 [英] Laravel 4 always returns HTTP status code 200

查看:400
本文介绍了Laravel 4始终返回HTTP状态代码200的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在error.php中有以下代码,该代码是使用控制器中的App::abort(404, $error)触发的.我的响应状态代码仍然是200(确定).我尝试了各种错误代码,例如400、403

I have below code in error.php, which is triggered using App::abort(404, $error) in my controller. Still my response status code is 200(ok). I tried with various error codes like 400, 403

// NotFoundException handler
App::error(function(NotFoundException $e)
{
    $default_message = 'The requested resource was not found';

    return Response::json(array(
        'error' => $e->getMessage() ?: $default_message,
    ), 404);
 });

推荐答案

对于仍在使用此问题的人:

For anyone still googling this problem:

我在这个问题上苦苦挣扎了好几个小时.对我来说,问题是由我的一个控制器出现问题引起的.

I was struggling with this problem for hours. For me the problem was caused by an issue with one of my controllers.

检查所有控制器,并确保<?php标记前面没有空格. < ?php标记应该是文件中的第一件事.在任何这样路由的控制器中,<?php标记前面的单个空格:

Check all of your controllers and make sure there are no spaces in front of the <?php tag. The <?php tag should be the very first thing in the file. A single space in front of the <?php tag in any of your controllers that are routed as such:

Route::controller('example', 'ExampleController');

将导致所有状态代码均为200.

Will cause all status codes to be 200.

这篇关于Laravel 4始终返回HTTP状态代码200的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆