I am trying to make an API with PHP and JSON, however I am stuck on extracting the JSON on the receiving/API side of the request.
So I am doing this on the client end of my transaction:
$data = array("test" => "test");
$data_string = json_encode($data);
$ch = curl_init('https://..../api/v1/functions? key=TPO4X2yCobCJ633&aid=9&action=add');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$return = curl_exec($ch);
But how do I receive and extract the POSTed data on the server (receiving) side of the transaction (inside my API)?
Summary:
What i mean is i have a client that is sending a JSON file to the API now i what i don't understand is how can i get the API side to see and extract/see the data
$return. That will be your resulting json string.var_dump($return). Add the output to the code to help you out further.curl_close($ch);