2015-07-21 33 views
0

我有一個名爲「posted.php」的頁面。我將數據發佈到postjson.php。這是正常的。但是,如何捕捉那些發佈數據postjson.php從Php Curl post獲得回覆

posted.php的代碼如下:

**$url = 'http://localhost/Sudips/json/postjson.php'; 

//Initiate cURL. 
$ch = curl_init($url); 

//The JSON data. 
$data = array("name" => "Hagrid", "age" => "36");                  
$data_string = json_encode($data);                     

$ch = curl_init($url);                  
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                  
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);                 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                  
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 
    'Content-Type:application/json', 
    'Content-Length: ' . strlen($data_string))                  
);                             

$result = curl_exec($ch);** 

我需要得到這些數據發表在postjson.php。如何讓他們在postjson.php。我想在postjson.php中使用$ _POST,但它什麼也沒有顯示。

+0

在postjson.php嘗試'的var_dump($ _ POST)'和posted.php加上'回聲$結果' – Scott

+0

'var_dump($ _ POST)'在** postjson.php **中給了你什麼?並且你可以在postjson.php中添加'if(curl_errno($ ch)){echo curl_error($ ch);}'到** posted.php ** – DavidDomain

+0

它返回數組(0){} –

回答

0

你是否在某處返回$ result變量?

+0

應該是一個註釋 – Scott

+0

我的名聲不符合我的意見。 ;) –

+0

我已經在posted.php中打印了$結果,它顯示了發佈的數組,但是我想將它們打印在postjson.php頁面中,數據發佈到哪裏。 –

1

您正在傳遞下面的curl請求的值,然後回顧變量的值,然後展開|然後存儲在變量中。

須藤的/ usr /斌/捲曲-o 「MAC_ID = $夥伴| $密碼| $ credit_point」 http://www.example.com/credit_request_cloud.php

$ MAC_ID =修剪($ _ REQUEST [ 'MAC_ID']);

$ array =(explode(「 - 」,$ mac_id));

$ mac_id = $ array [0];

$ rand_no = $ array [1];

1

嘗試使用任何的file_get_contents( 「PHP://輸入」)或HTTP_RAW_POST_DATA在postjson.php文件