【问题标题】:Throw a custom 401 HTTP Exception in Kohana在 Kohana 中引发自定义 401 HTTP 异常
【发布时间】:2013-04-19 09:24:53
【问题描述】:

当我在Kohana 3.3 中抛出HTTP_Exception_401 时,我收到以下错误:

Kohana_Exception [ 0 ]: A 'www-authenticate' header must be specified for a HTTP 401 Unauthorized

现在明显的问题是 www-authenticate 标头尚未设置。

我正在努力弄清楚如何以及在何处设置它。
我尝试了以下方法,但抛出了同样的错误:

使用原生 PHP header():

header('WWW-Authenticate: realm="My Website"');
throw new HTTP_Exception_401('Authorisation Required');

向请求对象添加标头:

$this->request->header('WWW-Authenticate', 'realm="My Website"');
throw new HTTP_Exception_401('Authorisation Required');

我正在尝试从控制器抛出异常。
任何帮助将不胜感激。

【问题讨论】:

    标签: php kohana http-status-code-401 kohana-3.3 www-authenticate


    【解决方案1】:

    正如upgrage guide 所说:

    // Unauthorized / Login Requied
    throw HTTP_Exception::factory(401)->authenticate('Basic realm="MySite"');
    

    【讨论】:

    • 在响应中定义没有帮助......但使用HTTP_Exception::factory()... 确实。干杯。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多