0

I'm creating an api using php and I'm using postman to test my requests.

in postman I choose the method of posting and in body use the raw to send a json to my api

category{
    "id":"1",
    "desc": "testing",
    "observation": "testing",
}

it sends perfectly, but how can I recover my json on the server side? in my php

i'm using

$result = json_decode($_POST['category'], true);

but the error occurs

 Notice: Undefined index: category in

Postman

Emiry Mirella
  • 567
  • 1
  • 7
  • 21

1 Answers1

7

If the data is in the actual body you might need to retrieve it instead of looking in the $_POST array:

Try this:

$body = file_get_contents('php://input');
echo $body;

As seen in the comments of the question, you can use json_decode() to get a php object.

$object = json_decode($body);
echo '<pre>';
print_r($object);
echo '</pre>';
Jeppsen
  • 487
  • 3
  • 10