I have made my own API endpoint, but for some reason when I call this endpoint with postman, the file_get contents is always empty...
if(isset($_GET['type']) AND $_GET['type'] == "new")
{
$inputJSON = file_get_contents('php://input');
if($inputJSON)
{
$body = json_decode($inputJSON, true); //convert JSON into array
}
else{
header("HTTP/1.1 403 Bad request");
$response = array(
'status' => 'Error',
'message' => 'Invalid body'
);
}
}
The request im doing in postman looks like this:
Does anyone know why the body is always empty? It should contain JSON data..
By adding a /
to the end of the endpoint it worked.
The addition of a slash at the end of a URL instructs the web server to search for a directory.
My server might issue a redirect for the version with a trailing slash, and if the client follows that by making a GET request, I lose all POST data at this point.
Thanks to @C3roe