I'm using curl to post json data to a rest endpoint which is in php. This is being done in an integration test. Surprisingly, entire json object is available to me in $_POST on the server. How is this possible ? Here's my php code which posts the json :
$data = array(
'username' => 'blahbah',
'password' => 'blahblah',
'grant_type' => 'client_credentials',
'client_id' => 'blah',
'client_secret' => 'blah'
);
$data_string = json_encode($data);
$this->curl = curl_init($this->tokenApi);
curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($this->curl, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($this->curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string));
$response = curl_exec($this->curl);
On the api side , if I do a print_r($_POST), I get:
Array
(
[username] => blahbah
[password] => blahblah
[grant_type] => client_credentials
[client_id] => blah
[client_secret] => blah
)
How is this possible ? From what I have read, the json string should only be available as "php//input". I'm a bit confused about what's the correct way to access the json. I'm using PHP 5.4.
Thanks.