I am firing a curl request from command line.
My curl request looks like:
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
My PHP code:
<?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);
}
?>
but $_SERVER doesn't seems to have json data. Did i miss something??
POSTwhen you don't recognize the request method. Instead you should return a 405 HTTP error. Maybe you received aHEADrequest...