A. Duff
A. Duff

Reputation: 4309

Retrieving parameters from PUT request

In Symfony2, I'm trying to set up a controller that responds to PUT requests and retrieves parameters from the headers associated with the request (which I'm entering using Postman). The page is loading fine, but is not getting any values from the headers.

This is my routing.yml file:

mybundle_foo:
    pattern: /foo
    defaults: {_controller: myBundle:Default:foo }
    requirements: {_methods: put, _format: html}

In the controller:

public function fooAction (Request $request) {
  $someParam = $request->request->get('someParam');
  return new Response("Some param is $someParam", 200);
}

When sending a PUT request to the URL with Postman, with a header with a key of "someParam" and a value of "bar," the output I get is just Some param is

I had thought that you would get the headers in the same way as you do with a POST request, but I guess not. Is there any way to get the headers for a PUT request?

Upvotes: 0

Views: 2333

Answers (2)

Alberto Gaona
Alberto Gaona

Reputation: 2437

To get a parameter from the header:

$someParam = $request->headers->get("someParam");

Upvotes: 2

Alex Pliutau
Alex Pliutau

Reputation: 21957

The problem in $request->request. You should use:

$request->get('someParam');

Also check this in your controller:

var_dump($_PUT['someParam']);

Upvotes: 0

Related Questions