1
我在postman中使用POST將JSON消息發送到了我的web服務器。但是回顯只顯示GET並且沒有消息。我認爲回顯應顯示POST不GET。下面的代碼正在工作,但格式不是JSON。請看下面的圖片:使用php(REST API)在web服務器中進行錯誤的通信
<html>
<head></head>
<body>
<?php
$method = $_SERVER['REQUEST_METHOD'];
$url = 'http://115.145.163.244:5851/TEST52.php';
echo $method;
echo "<br />\n";
switch ($method) {
case 'POST':
$input = json_decode(file_get_contents('php://input'), true);
break;
case 'GET':
$input = json_decode(file_get_contents('php://input'), true);
break;
case 'PUT':
$input = json_decode(file_get_contents('php://input'), true);
break;
case 'DELETE':
$input = json_decode(file_get_contents('php://input'), true);
break;
}
echo ($input->data->ContextID); //it does not work
print_r($input); //it does work. But not in JSON format
?>
</body>