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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信会员卡接入微信支付商户号收款
    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?