-1

Due to this problem I have summarized the error in the most basic example to find a solution. I have a PHP file with the following code:

if( isset($_POST['nombre']) ){
        echo("Do thing");
   }
else{
    echo("Error");
}

If I send the NAME data from a post form, it enters the IF without problem. If from Postman I try to send a data from BODY FORM-DATA or x-www.form.urlencoded, the POST arrives without problem and enters the IF.

{"nombre": "fdsf"}

But if I send a JSON from postman, something like $_POST['name'] comes back empty and being empty does not enter the IF

Does anyone know why it happens?.

Fran Pino
  • 111
  • 7

1 Answers1

1

Try 'php://input' It allows us to read raw data from the request body, regardless of the content type. Try this

$json = file_get_contents('php://input');
        $data = json_decode($json);

        return print_r($data);
Haris
  • 71
  • 3