[英]Get response from Php Curl post
我有一個名為“ posted.php”的頁面。 我從中將數據發布到postjson.php。 那正在發生。 但是如何在postjson.php中捕獲那些發布的數據
posts.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,但它什么也沒顯示。
您正在傳遞如下curl請求的值,然后獲取變量的值,然后展開| 然后存儲在變量中。
sudo / usr / bin / curl -o“ mac_id = $ partner | $ password | $ credit_point” http://www.example.com/credit_request_cloud.php
$ mac_id = trim($ _ REQUEST ['mac_id']);
$ array =(explode(“-”,$ mac_id));
$ mac_id = $ array [0];
$ rand_no = $ array [1];
嘗試在postjson.php文件中使用file_get_contents(“ php:// input”)或HTTP_RAW_POST_DATA
您是否要在某個地方返回$ result變量?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.