获取请求ZF2控制器中的授权头 [英] Getting request Authorization header in ZF2 controller
问题描述
我使用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.
推荐答案
我终于找到了答案:
无法将以下内容添加到项目.htaccess中:
Had to add the following to the projects .htaccess:
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
这篇关于获取请求ZF2控制器中的授权头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!