今天就跟大家聊聊有關使用php怎么接收和處理 post、json參數,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結了以下內容,希望大家根據這篇文章可以有所收獲。

1.php
<?
function http_post_data($url, $data_string) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json; charset=utf-8',
'Content-Length: ' . strlen($data_string))
);
ob_start();
curl_exec($ch);
$return_content = ob_get_contents();
//echo $return_content."<br>";
ob_end_clean();
$return_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// return array($return_code, $return_content);
return $return_content;
}
$url = "http://127.0.0.1/2.php";
$data = json_encode(array('a'=>"weqweqwe", 'b'=>2));
//list($return_code, $return_content) = http_post_data($url, $data);
$aaa = http_post_data($url, $data);
//print_r($aaa);
echo $aaa;
$ccc=json_decode($aaa);
print_r($ccc);
echo $ccc->b;
echo "<hr>";
$json = '{"a":1,"b":2,"c":3,"d":4,"e":5}';
var_dump(json_decode($json,true));
?>頁面2,參數接收處理:
2.php
<?
$postData = file_get_contents('php://input');
echo $postData;
$data = json_encode(array('a'=>" 234 ", 'b'=>2));
echo $data;
?>一、phpStudy,是一個新手入門最常用的開發環境。二、WampServer,WampServer也同樣的也是和phpStudy一樣操作簡單對小白比較友好。三、XAMPP,XAMPP(Apache+MySQL+PHP+PERL)是一個功能強大的建站集成軟件包;四、MAMP,MAMP分為兩種MAMP和MAMP Pro for Mac。五、寶塔面板,寶塔面板是一款服務器管理軟件,支持windows和linux系統。六、UPUPW,UPUPW是目前Windows平臺下最具特色的Web服務器PHP套件。
看完上述內容,你們對使用php怎么接收和處理 post、json參數有進一步的了解嗎?如果還想了解更多知識或者相關內容,請關注創新互聯行業資訊頻道,感謝大家的支持。
文章標題:使用php怎么接收和處理post、json參數-創新互聯
文章路徑:http://www.yijiale78.com/article12/cshodc.html
成都網站建設公司_創新互聯,為您提供企業建站、App設計、標簽優化、網站制作、定制開發、微信公眾號
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯