Search code examples
symfonyhttp-headershttpwebrequest

How to get request header values in symfony


Am using symfony frame work in my application to make rest web service. I want to get request header values in controller method. Is there any way to achieve it.


Solution

  • You need to pass your Request object to the controller method and then in controller use $request->headers->all()

    For example:

    public function testAction(Request $request)
    {
        $headers = $request->headers->all();
    }
    

    You can also get Request object from a controller by calling $this->getRequest() from controller method.