获取请求ZF2控制器中的授权头 [英] Getting request Authorization header in ZF2 controller

查看:181
本文介绍了获取请求ZF2控制器中的授权头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ZF2和某些原因,我可以得到所有的标头我发送EXCEPT授权头 - 它就像它的过滤掉。

I am using ZF2 and for some reason, I can get all the headers I send EXCEPT the Authorization header - it's like its filtered out.

我试图获取控制器中的所有标头,如下所示:

I am trying to get all the headers in the controller like this:

    public function createAction($data) 
    {
        $request  = $this->request;
        print_r ($request->getHeaders());
        exit();

    }



我通过cURL发送请求,如下:

I send the request through cURL like this:

curl -i -H "Accept: test" -H "Authorization: 123456" -H "Content-Type: qwerty" -X POST http://localhost/test

所有头都打印出EXCEPT授权头。我可以添加任何任意头,它打印出来 - 只是没有'授权'头...

All headers prints out EXCEPT authorization header. I can add any arbitrary header and it prints it out - just no the 'Authorization' header...

我也试图get()/ has

I've also tried to get()/has() for the authorization header, yet it does not exist.

推荐答案

我终于找到了答案:

http://zend-framework-community.634137.n4.nabble.com/HTTP-Digest-authentication-does-not-work-with-PHP-as-CGi-td4658790 .html

无法将以下内容添加到项目.htaccess中:

Had to add the following to the projects .htaccess:

RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

这篇关于获取请求ZF2控制器中的授权头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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