duanjiongzhen2523 2017-06-02 05:32
浏览 51

为什么我的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";

?>
  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥15 c++头文件不能识别CDialog
    • ¥15 Excel发现不可读取的内容