# PUT request body params

**URL:** <https://discourse.slimframework.com/t/put-request-body-params/2054>\
**Category:** Questions\
**Created:** [November 29, 2017, 7:26am UTC](https://discourse.slimframework.com/t/put-request-body-params/2054 "2017-11-29T07:26:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![qwertytest](https://avatars.discourse-cdn.com/v4/letter/q/a6a055/32.png) [@qwertytest](https://discourse.slimframework.com/u/qwertytest)\
**Post date:** [November 29, 2017, 7:26am UTC](https://discourse.slimframework.com/t/put-request-body-params/2054/1 "2017-11-29T07:26:56Z")

</div>

I’m having troubles getting the body params parsed from a PUT request.  
I’ve read some issues/pull on github, but finally I got no solution.  
Any workaround to get this “fixed”? Shoul I set any specific content type  
or somehow simulate a POST? Many thanks in advance.

I’m using latest slim.

---

<div class="post-metadata">

**Author:** ![odan](https://avatars.discourse-cdn.com/v4/letter/o/9de053/32.png) [@odan](https://discourse.slimframework.com/u/odan)\
**Post date:** [November 29, 2017, 9:02am UTC](https://discourse.slimframework.com/t/put-request-body-params/2054/2 "2017-11-29T09:02:51Z")

</div>

Do you have an example?

Have you tried this?

> [@Slim v3 PUT method and retrieve POST data](http://discourse.slimframework.com/t/slim-v3-put-method-and-retrieve-post-data/849):
>
> I have added route to update emails in a database which uses PUT method $app-\>put('/notifications/{email}', 'add\_email\_address'); and function for it looks like: function add\_email\_address($request, $response, $args) { $email = $args['email']; $addon\_email = $request-\>getParam('addon\_email', null); echo "ADD/UPDATE $email with $addon\_email"; } somehow on testing PUT method with a form input post addon\_email = [test@null.com](mailto:test@null.com) retrieved value for $addon\_email is empty Any tips…

---

<div class="post-metadata">

**Author:** ![qwertytest](https://avatars.discourse-cdn.com/v4/letter/q/a6a055/32.png) [@qwertytest](https://discourse.slimframework.com/u/qwertytest)\
**Post date:** [November 29, 2017, 10:45am UTC](https://discourse.slimframework.com/t/put-request-body-params/2054/3 "2017-11-29T10:45:26Z")

</div>

I’ve tried setting content type to: application/x-www-form-urlencoded, then:

$bodyParams = $request-\>getParsedBody();  
var\_dump($bodyParams[‘myParam’]);

but I cannot access myParam inside the array, because it is sorrounded with encoding…

---

<div class="post-metadata">

**Author:** ![odan](https://avatars.discourse-cdn.com/v4/letter/o/9de053/32.png) [@odan](https://discourse.slimframework.com/u/odan)\
**Post date:** [November 29, 2017, 4:09pm UTC](https://discourse.slimframework.com/t/put-request-body-params/2054/4 "2017-11-29T16:09:01Z")

</div>

Aha you are trying the get POST variables from a PUT request.

In Slim 3 the POST variables are only parsed if the request

1. method is POST and
2. the media type is: ‘application/x-www-form-urlencoded’ or ‘multipart/form-data’.

Let’s try this (not tested):

```
$parsedBody = $request->getParsedBody();
parse_str($parsedBody, $postData);

print_r($postData);

```

PS: According to the HTTP specification RFC 7231 (Section 4.3.4), the PUT request can have a payload. Therefore, it must be parsed in the slim Request implementation. Looks like a bug to me.

More infos:  
[https://tools.ietf.org/html/rfc7231#section-4.3.4](https://tools.ietf.org/html/rfc7231#section-4.3.4)

> <https://stackoverflow.com/questions/5905916/payloads-of-http-request-methods>

---

<div class="post-metadata">

**Author:** ![qwertytest](https://avatars.discourse-cdn.com/v4/letter/q/a6a055/32.png) [@qwertytest](https://discourse.slimframework.com/u/qwertytest)\
**Post date:** [December 1, 2017, 4:40pm UTC](https://discourse.slimframework.com/t/put-request-body-params/2054/5 "2017-12-01T16:40:16Z")

</div>

Looks like a bug to me too.  
Your solution is nearly ok, but return an empty array, meanwhile I found this workaround:

parse\_str(file\_get\_contents(‘php://input’), $bodyParams);

is this accetable/secure? Many thanks for your time.

---

<div class="post-metadata">

**Author:** ![odan](https://avatars.discourse-cdn.com/v4/letter/o/9de053/32.png) [@odan](https://discourse.slimframework.com/u/odan)\
**Post date:** [December 4, 2017, 11:29am UTC](https://discourse.slimframework.com/t/put-request-body-params/2054/6 "2017-12-04T11:29:41Z")

</div>

Slim is a PSR-11 based micro framework. So you must use the `Request` object and not the vanilla php functions.

e.g.

`parse_str($request->getBody()->getContents(), $bodyParams);`

Question: Why don’t you send JSON via PUT?
