我正在从命令行发出 curl 请求。
我的 curl 请求如下所示:
curl -X POST -H "Accept: application/json" -H "Content-type: application/json" -d '{ "BookingByCustomer" : "testUser", "BookingDate" : "11111111", "TotalCost" : "11", "NetAmount" : "11" }' http://serverIP:port/test.php
我的PHP代码:
<?php
/** global variables */
$request_called = ($_SERVER['REQUEST_METHOD'] == 'GET') ? 'GET' : 'POST';
if($request_called == 'POST')
{
handle_post_request();
}
if($request_called == 'GET')
{
handle_get_request();
}
function handle_get_request (){
echo "Get Request has been called!";
}
function handle_post_request (){
$json = $_SERVER['HTTP_JSON'];
print_r ($_SERVER);
}
?>
但 $_SERVER 似乎没有 json 数据。我错过了什么??