为什么我的GET请求不是使用PHP cURL发送的?

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";

?>
dourui7186
dourui7186 不,我没有在屏幕上得到任何东西:s
3 年多之前 回复
dongtiao2105
dongtiao2105 打开错误。写入ini_set('error_reporting',E_ALL);ini_set('display_errors','On');在您的脚本中,看看您是否收到任何错误
3 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐