【问题标题】:Get HTTP status text in PHP or Laravel在 PHP 或 Laravel 中获取 HTTP 状态文本
【发布时间】:2016-03-08 23:24:11
【问题描述】:

在 Chrome 检查器中,当我点击 404 时,我看到:

Request URL:http://myapp.dev/doesnotexist
Request Method:GET
Status Code:404 Not Found
Remote Address:192.X.X.X:80

到目前为止,我只能通过使用$exception->getStatusCode()获得数字代码“404”

有没有办法在 PHP(或 Laravel)中获取“未找到”的文本描述?

【问题讨论】:

  • 你在使用 cURL 吗?看起来curl_error() 会返回此信息。
  • 我安装了 cURL,但他的错误不是来自 cURL 请求,所以我认为这不会起作用。
  • 如果 Laravel 没有为此提供 API,你可能需要使用 cURL。
  • @Barmar 我认为 OP 是在提供网络服务,而不是在消费。

标签: php http-headers laravel-5.1 http-error


【解决方案1】:

您是否已将您的 app/config/app.php 更改为:

'debug' => env('APP_DEBUG', true),

【讨论】:

  • 我需要它在生产中工作(关闭调试),因为我想向最终用户显示错误文本以进行故障排除。
【解决方案2】:

如果要显示Custome 404 Error页面,可以在views/errors目录下创建404.blade.php文件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-11
    • 2013-12-06
    • 1970-01-01
    • 2023-04-09
    • 1970-01-01
    • 2018-09-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多