# Post request return null

**URL:** <https://discourse.slimframework.com/t/post-request-return-null/4107>\
**Category:** Questions\
**Created:** [April 29, 2020, 8:14am UTC](https://discourse.slimframework.com/t/post-request-return-null/4107 "2020-04-29T08:14:13Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![reizzzor](https://avatars.discourse-cdn.com/v4/letter/r/6de8d8/32.png) [@reizzzor](https://discourse.slimframework.com/u/reizzzor)\
**Post date:** [April 29, 2020, 8:14am UTC](https://discourse.slimframework.com/t/post-request-return-null/4107/1 "2020-04-29T08:14:13Z")

</div>

Hi. Please HELP.  
Such problem. I do everything according to the video guide. When I send data via postman and process it via getParsedBody (), it returns null.

```php
    use Psr\Http\Message\ResponseInterface as Response;
    use Psr\Http\Message\ServerRequestInterface as Request;
    use Slim\Factory\AppFactory;

    require __DIR__. '/../vendor/autoload.php';

    $app = AppFactory::create();
    $app->get('/', function (Request $request, Response $response) {
        $response->getBody()->write("Hello, World!");

        return $response;
    });

    $app->post('/users', function (Request $request, Response $response, $args) {
        header("Content-Type: application/json;");
        $requestData = $request->getParsedBody();
        print_r($requestData);
        return $response;
    });

```

IMG

> **Summary**
>
> ![2020-04-29_11-08-49](https://canada1.discourse-cdn.com/flex030/uploads/slimframework/original/2X/c/c17fdcf29cb910bfad114916f7b54cb03e9b53ef.png)  
> ![2020-04-29_11-06-29](https://canada1.discourse-cdn.com/flex030/uploads/slimframework/original/2X/4/4ddccfb03a714c5a4b9a32b6b56a9b74e438b8ed.png)  
> ![2020-04-29_11-10-57](https://canada1.discourse-cdn.com/flex030/uploads/slimframework/original/2X/a/a62c8a3bfd50ffc10a66267a644bd3558c4b5ad1.png)  
> ![2020-04-29_11-11-24](https://canada1.discourse-cdn.com/flex030/uploads/slimframework/original/2X/a/ae23d526021646b1235f8da1fa826d676bdf064d.png)

---

<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:** [April 29, 2020, 10:39am UTC](https://discourse.slimframework.com/t/post-request-return-null/4107/2 "2020-04-29T10:39:11Z")

</div>

> getParsedBody (), it returns null.

1. Have you tried to add the BodyParsingMiddleware?

```php
$app->addBodyParsingMiddleware();

```

1. Your (HTTP) client must send the correct request header value `Content-Type: application/json`

![image](https://canada1.discourse-cdn.com/flex030/uploads/slimframework/original/2X/5/59a7f3f2fcf6027da0c8512c1f5d7a2d6c845f10.png)

Read more: [Difference between Accept and Content-Type HTTP headers](https://webmasters.stackexchange.com/a/31231)

> header(“Content-Type: application/json;”);

Better don’t use the vanilla header() function in Slim. To manipulate the response headers use the $response object instead.

> Cannot register two routes…

Make sure, that your routes are not overlapping. Don’t define the same route twice.

---

<div class="post-metadata">

**Author:** ![reizzzor](https://avatars.discourse-cdn.com/v4/letter/r/6de8d8/32.png) [@reizzzor](https://discourse.slimframework.com/u/reizzzor)\
**Post date:** [April 29, 2020, 11:38am UTC](https://discourse.slimframework.com/t/post-request-return-null/4107/3 "2020-04-29T11:38:39Z")

</div>

Thanks for the answer. But it didn’t help. Can there be more tips?  
I have already spent a lot of time searching for a solution to this problem…

> **Summary**
>
> ![2020-04-29_14-33-08](https://canada1.discourse-cdn.com/flex030/uploads/slimframework/original/2X/c/c47d8d99430a2c7f171719e9ae44c3633b46470d.png)  
> ![2020-04-29_14-34-04](https://canada1.discourse-cdn.com/flex030/uploads/slimframework/original/2X/3/3223547ec5021effa44d39eeac38714f23bad7bc.png) ![2020-04-29_14-36-20](https://canada1.discourse-cdn.com/flex030/uploads/slimframework/original/2X/3/37c68c1ba7f7e77113d3dfce8ea148d886711a90.png)  
> ![2020-04-29_14-44-47](https://canada1.discourse-cdn.com/flex030/uploads/slimframework/original/2X/d/dd14d609fffb341b5053cc8bb2f6ce94520b8e99.png)

---

<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:** [April 29, 2020, 1:31pm UTC](https://discourse.slimframework.com/t/post-request-return-null/4107/4 "2020-04-29T13:31:55Z")

</div>

> [@odan](#):
>
> Your (HTTP) client must send the correct request header value `Content-Type: application/json`

The request `Content-Type` is missing now, it’s **required**.

---

<div class="post-metadata">

**Author:** ![reizzzor](https://avatars.discourse-cdn.com/v4/letter/r/6de8d8/32.png) [@reizzzor](https://discourse.slimframework.com/u/reizzzor)\
**Post date:** [April 29, 2020, 1:59pm UTC](https://discourse.slimframework.com/t/post-request-return-null/4107/5 "2020-04-29T13:59:00Z")

</div>

All the same, friend

> **Summary**
>
> ![2020-04-29_16-54-49](https://canada1.discourse-cdn.com/flex030/uploads/slimframework/original/2X/8/87072aac89babf83edc6bbc0ce3952b783953b5d.png)  
> ![2020-04-29_16-54-14](https://canada1.discourse-cdn.com/flex030/uploads/slimframework/original/2X/9/9fa01ac32665801d66a73bbddf87aef91b0acde7.png)

---

<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:** [April 29, 2020, 2:11pm UTC](https://discourse.slimframework.com/t/post-request-return-null/4107/6 "2020-04-29T14:11:42Z")

</div>

Please show us your request body content.

---

<div class="post-metadata">

**Author:** ![reizzzor](https://avatars.discourse-cdn.com/v4/letter/r/6de8d8/32.png) [@reizzzor](https://discourse.slimframework.com/u/reizzzor)\
**Post date:** [April 29, 2020, 2:35pm UTC](https://discourse.slimframework.com/t/post-request-return-null/4107/7 "2020-04-29T14:35:17Z")

</div>

I should have sent it like this? Through the body and not params? 🙂

 ![2020-04-29_17-32-14](https://canada1.discourse-cdn.com/flex030/uploads/slimframework/original/2X/d/dcd600a01014ef1ad90ecc5040cd54400b9362e0.png)

---

<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:** [April 29, 2020, 2:40pm UTC](https://discourse.slimframework.com/t/post-request-return-null/4107/8 "2020-04-29T14:40:09Z")

</div>

> I should have sent it like this? Through the body and not params?

Yes, look at your first question 🙂

getParsed **Body** ()

> $requestData = $request-\>getParsedBody();

Maybe I just don’t get your question right. Are you trying to send JSON or form-data to the server?

If JSON set the correct Content-Type Header and switch the mode from form-data to RAW → JSON

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/slimframework/original/2X/7/734ab960291b9979d4bad5058c239b5be042f327.png)

---

<div class="post-metadata">

**Author:** ![reizzzor](https://avatars.discourse-cdn.com/v4/letter/r/6de8d8/32.png) [@reizzzor](https://discourse.slimframework.com/u/reizzzor)\
**Post date:** [April 29, 2020, 2:51pm UTC](https://discourse.slimframework.com/t/post-request-return-null/4107/9 "2020-04-29T14:51:05Z")

</div>

Route processes the request. Everything is working out well and now I need to send requests like this?

 ![2020-04-29_17-48-28](https://canada1.discourse-cdn.com/flex030/uploads/slimframework/original/2X/5/545afdf8badbc10ae45985914681874575b79d13.png)

---

<div class="post-metadata">

**Author:** ![reizzzor](https://avatars.discourse-cdn.com/v4/letter/r/6de8d8/32.png) [@reizzzor](https://discourse.slimframework.com/u/reizzzor)\
**Post date:** [April 29, 2020, 2:53pm UTC](https://discourse.slimframework.com/t/post-request-return-null/4107/10 "2020-04-29T14:53:30Z")

</div>

I was given a test task. I need to make a simple api to output, add, and delete a user saved to a json file

---

<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:** [April 29, 2020, 2:55pm UTC](https://discourse.slimframework.com/t/post-request-return-null/4107/11 "2020-04-29T14:55:58Z")

</div>

> Everything is working out well and now I need to send requests like this?

If you want to implement a working RESTful API with JSON then yes 🙂

---

<div class="post-metadata">

**Author:** ![reizzzor](https://avatars.discourse-cdn.com/v4/letter/r/6de8d8/32.png) [@reizzzor](https://discourse.slimframework.com/u/reizzzor)\
**Post date:** [April 29, 2020, 4:01pm UTC](https://discourse.slimframework.com/t/post-request-return-null/4107/12 "2020-04-29T16:01:23Z")

</div>

Thank you very much, friend. I can’t tell you how grateful I am. I stayed up all night trying to solve the problem 🙂

---

<div class="post-metadata">

**Author:** ![pauloreis](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/pauloreis/32/1165_2.png) [@pauloreis](https://discourse.slimframework.com/u/pauloreis)\
**Post date:** [May 5, 2020, 7:19pm UTC](https://discourse.slimframework.com/t/post-request-return-null/4107/14 "2020-05-05T19:19:54Z")

</div>

$requestData = $request-\>getBody()-\>getContents();
