如下所示:
?php $weather = curl_init(); curl_setopt($weather,CURLOPT_URL,"https://api.pc2801.com/cqssc/".time()); curl_setopt($weather, CURLOPT_SSL_VERIFYPEER, false); //如果接口URL是https的,我們將其設為不驗證,如果不是https的接口,這句可以不用加 curl_setopt($weather,CURLOPT_RETURNTRANSFER,true); $data = curl_exec($weather); curl_close($weather); $data=json_decode($data,true);//將json格式轉(zhuǎn)化為數(shù)組格式,方便使用 ?>
以上這篇PHP通過curl獲取接口URL的數(shù)據(jù)方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。