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 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 对于相关问题的求解与代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料