get請求是最簡單的請求,不過要注意自己的請求是http請求還是https的請求,因?yàn)閔ttps請求時(shí)要關(guān)閉SSL驗(yàn)證,不然驗(yàn)證通不過,沒有辦法請求到數(shù)據(jù)。
GET請求的參數(shù)
get傳遞參數(shù)和正常請求url傳遞參數(shù)的方式一樣
function get_info($card){ $url ="http://www.sdt.com/api/White/CardInfo?cardNo=".$bank_card; $ch = curl_init(); //設(shè)置選項(xiàng),包括URL curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); //執(zhí)行并獲取HTML文檔內(nèi)容 $output = curl_exec($ch); //釋放curl句柄 curl_close($ch); return $output; }
HTTPS請求時(shí)要注意SSL驗(yàn)證
function get_bankcard_info($bank_card){ $url ="https://ccdcapi.alipay.com/validateAndCacheCardInfo.json?_input_charset=utf-8&cardNo=".$bank_card."&cardBinCheck=true"; $ch = curl_init(); //設(shè)置選項(xiàng),包括URL curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);//繞過ssl驗(yàn)證 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //執(zhí)行并獲取HTML文檔內(nèi)容 $output = curl_exec($ch); //釋放curl句柄 curl_close($ch); return $output; }
以上就是關(guān)于在php中使用curl發(fā)送get請求時(shí)參數(shù)傳遞問題的解析的詳細(xì)內(nèi)容,更多請關(guān)注創(chuàng)新互聯(lián)其它相關(guān)文章!