0

How can I get PUT body parameters using HttpFoundation component (without Symfony)? According the docs Request::createFromGlobals only about POST, GET ... but not PUT. So here I cannot use like $request->request->all(), it will be empty.

I believe there is a more nicer way then

$request = Request::createFromGlobals;
$content = $request->getContent();
// Parsing $content

This way json_decode($request->getContent(), true); returns null.

Please share your experience.

Philipp Maurer
  • 2,480
  • 6
  • 18
  • 25
  • Body parameters will be contained in `$_POST`, even if method is `PUT`. There is no `$_PUT` in PHP, only `$_GET` and `$_POST`. – N.B. Mar 16 '18 at 12:45
  • Yes, so here I'm asking in terms of HttpFoundation. – Elena Forester Mar 16 '18 at 14:07
  • What are you asking exactly? Just use `Request::createFromGlobals()` and it'll work fine, there's no black magic going on. – N.B. Mar 16 '18 at 14:09
  • https://joshtronic.com/2014/06/01/how-to-process-put-requests-with-php/ – Vinay Mar 16 '18 at 15:57
  • `Request::createFromGlobals()request->all()` for POST is ok, I can get params, but on PUT it returns null. – Elena Forester Mar 16 '18 at 16:37
  • I found out that it's not related to HttpFoundation. When I make POST request `var_dump($_POST)` gives proper params. But when I change to PUT the `$_POST` is empty. I'm using Postman for testing. – Elena Forester Mar 16 '18 at 17:12
  • 1
    Ok, I think I've solved my problem. Everything is ok when use `x-www-form-urlencoded`. – Elena Forester Mar 16 '18 at 17:27

0 Answers0