I am trying to send a JSON string through a GET request from one system to another, using the PHP cURL library. Then I am trying to send back a JSON string from the second machine, back to the first machine.
The problem is that apparently, nothing is being sent from the first to the second machine, because when I run the PHP script in the first machine in the browser, the screen is blank.
How should I fix this?
Script in the first machine:
<?php
$extractedDataArray = array(
"DataFiles/datum.txt3" => "60340039"
);
$extractedDataJson = json_encode($extractedDataArray, JSON_FORCE_OBJECT);
$url = "http://AAA.BBB.CCC.DDD/TestTwo/index.php";
$result = json_decode(sendJsonByGet($url, $extractedDataJson));
echo $result;
function sendJsonByGet($url="http://AAA.BBB.CCC.DDD/TestTwo/index.php", $extractedDataJson) {
$curlObject = curl_init($url);
curl_setopt($curlObject, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($curlObject, CURLOPT_POSTFIELDS, $extractedDataJson);
curl_setopt($curlObject, CURLOPT_RETURNTRANSFER, 1);
curl_setopt( $curlObject, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Content-Length: ' . strlen($extractedDataJson) ) );
$result = curl_exec($curlObject);
curl_close($curlObject);
return $result;
}
Script in the Second Machine:
<?php
$dataJson = file_get_contents('php://input');
echo "Test Test Test<br><br>";
echo "RESULT RETURNED FROM AAA.BBB.CCC.DDD: $dataJson";
?>