Проверьте, если Post запрос php
Better use $_SERVER['REQUEST_METHOD']:
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// …
}
Lokesh003Coding
Better use $_SERVER['REQUEST_METHOD']:
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// …
}
//If you need the JSON part of the POST request, I use this code:
$jsonraw = file_get_contents('php://input');
$post_request = json_decode($jsonraw);
$requestMethod = $_SERVER["REQUEST_METHOD"];
switch ($requestMethod) {
case "POST":
if (isset($post_request->'id')) {
header("Content-Type:application/json; charset=utf-8");
header("HTTP/1.1 200");
die(json_encode(['result' => 'ok', 'data' => $post_request->id]));
} else {
header("Content-Type:application/json; charset=utf-8");
header("HTTP/1.1 500");
die(json_encode(['error' => 'id not found']));
}
break;
default:
header("Content-Type:application/json; charset=utf-8");
header("HTTP/1.1 404");
die(json_encode(['error' => 'not allowed']));
break;
}