处理cURL中的JSON响应

时间:2013-05-15 12:04:29

标签: php json curl null

我正在使用JSON处理cURL响应,但它只返回NULL。我不明白我在哪里做错了?

这是我的代码:

    <?php
        $data = array('name' => 'Hagrid','age' => '36');

        $bodyData = array('json' => json_encode($data));
        $bodyStr = http_build_query($bodyData);
        $url = 'http://bulk10.co.in/curl/index.php';

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded','Content-Length: '.strlen($bodyStr)));
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $bodyStr);

        $result = curl_exec($ch);
        echo $result;
    ?>

的index.php:

<?php
    $order_info = json_decode($_POST['json']);
    var_dump($order_info);
?>

任何人都可以帮助我,为什么我会收到NULL回复?

1 个答案:

答案 0 :(得分:0)

我当前服务器返回NULL的问题。其中一个Stack用户检查了这段代码并告诉他正在得到完美答案。然后我在不同的服务器上检查了这个,现在它的工作非常好。