PHP/Post 提交請求獲取json數據,並轉化為所需要的數組


/**
* Post 提交請求獲取json數據,並轉化為所需要的數組
*/

function request_post($url = '', $param = '') {
if (empty($url) || empty($param)) {
return false;
}

$postUrl = $url;
$curlPost = $param;
$ch = curl_init();//初始化curl
curl_setopt($ch, CURLOPT_URL,$postUrl);//抓取指定網頁
curl_setopt($ch, CURLOPT_HEADER, 0);//設置header
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求結果為字符串且輸出到屏幕上
curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
$data = curl_exec($ch);//運行curl
curl_close($ch);

return $data;
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM