php post调用api,PHP(CURL)POST数据调用API简单示例
/**
*@一個完整的POST調用API的過程 百度知道
*@author: bo.xiao
*/
$url = ‘http://zhidao.chanjet.com/restserver/zhidao’;
$data = array(
‘api_key’=>’3qQ2Edm62Vd4bAVCwNoxgn0l’,
‘method’=>’baidu.zhidao.getQuestionList’,
‘call_id’=>’1308713190’,
‘cid’=>59533,
‘qstatus’=>1,
‘format’=>’json’,
‘page_no’=>1,
‘page_size’=>25,
‘keywords’=>’財務’,
‘bd_sig’=>’2bad1c47bb75e0363a689f4b09743afb’
);
$json_data = postData($url, $data);
$array = json_decode($json_data,true);
echo ‘
’;print_r($array);function postData($url, $data)
{
$ch = curl_init();
$timeout = 300;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$handles = curl_exec($ch);
curl_close($ch);
return $handles;
}
?>
總結
以上是生活随笔為你收集整理的php post调用api,PHP(CURL)POST数据调用API简单示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java hashmap替换key,Ha
- 下一篇: 谈谈你对php的收获和不足,我的收获与不