I've created two php apis. One of them (API-1) needs to call the other (API-2) through post method. But when the second api is called,, the data is lost.
CODE
API 1 : http://mylocalsite.com/auth/register
// required headers
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Methods: POST");
header("Access-Control-Max-Age: 3600");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
// get posted data
$data = json_decode(file_get_contents("php://input"));
$url = "http://mylocalsite.com/user/create";
$client = curl_init($url);
curl_setopt($client, CURLOPT_RETURNTRANSFER, true);
curl_setopt($client, CURLOPT_POST, true);
curl_setopt($client, CURLOPT_POSTFIELDS, $data);
curl_setopt($client, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$response = curl_exec($client);
curl_close($client);
API 2 : http://mylocalsite.com/user/create
// required headers
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Methods: POST");
header("Access-Control-Max-Age: 3600");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
// get posted data
$data = json_decode(file_get_contents("php://input"));
// display data
var_dump($data);
Data sent
{
"username" : "anonymous_api",
"password" : "secret123!",
"firstname" : "anonymous_api",
"lastname" : "anonymous_api",
"email" : "anonymous_api@bookingpro.com",
"role" : "USER"
}
Expected data
{
"username" : "anonymous_api",
"password" : "secret123!",
"firstname" : "anonymous_api",
"lastname" : "anonymous_api",
"email" : "anonymous_api@bookingpro.com",
"role" : "USER"
}
Actual data
"NULL\n"
Thank you for your help :)