php - Symfony 2 中的请求 header 包缺少授权 header ?

标签 php http symfony http-headers fiddler

我正在尝试实现 custom authentication provider在 Symfony 2 中。我正在使用 Fiddler 发送测试请求并在服务器端打印所有 header ;好吧,Authorization header 丢失了。

我做错了什么吗?

GET /RESTfulBackend/web/index.php HTTP/1.1
Authorization: FID 44CF9590006BF252F707:jZNOcbfWmD/
Host: localhost
User-Agent: Fiddler
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: it-it,it;q=0.8,en-us;q=0.5,en;q=0.3

Listener 只打印标题并退出:

class HMACListener implements ListenerInterface
{
    private $securityContext;

    private $authenticationManager;

    public function handle(GetResponseEvent $event)
    {
        $request = $event->getRequest();
        print_r($request->headers->all()); 
        die();
     }
}

响应缺少 Authorization header :

Array
(
    [host] => Array
        (
            [0] => localhost
        )
    [user-agent] => Array
        (
            [0] => Fiddler
        )
    [accept] => Array
        (
            [0] => text/html,application/xhtml+xml,application/xml
        )
    [accept-language] => Array
        (
            [0] => it-it,it;q=0.8,en-us;q=0.5,en;q=0.3
        )
)

最佳答案

您必须将此代码添加到 virtualhost 标记

如果你把它放在目录标签里,它不会起作用。

    RewriteEngine On
    RewriteCond %{HTTP:Authorization} ^(.*)
    RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]

关于php - Symfony 2 中的请求 header 包缺少授权 header ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11990388/

相关文章:

c# - 如何使用 HTTP GET 接收传递给 ASP.NET 页面的值?

http - 如何在使用 camel-http 时设置代理

php - undefined _post 使用图像作为提交

php - 带有 CodeIgniter 的 REST API

php - 连接 MySQL 表,然后将结果过滤为列名

php - Laravel Eloquent JOIN 多个表

python - 如何使用 Python 发送没有 'Host Header' 的请求?

php - 覆盖 Doctrine 2.6 中特征属性的关联映射

php - Symfony 4 软删除与 Doctrine ORM

Symfony 2 -> Composer 和 CloudControl