關於在php中使用curl發送get請求時參數傳遞問題的解析


get請求是最簡單的請求,不過要注意自己的請求是http請求還是https的請求,因為https請求時要關閉SSL驗證,不然驗證通不過,沒有辦法請求到數據。

GET請求的參數

get傳遞參數和正常請求url傳遞參數的方式一樣

 1 function get_info($card){
 2   $url ="http://www.sdt.com/api/White/CardInfo?cardNo=".$bank_card; 
 3   $ch = curl_init();
 4   //設置選項,包括URL
 5   curl_setopt($ch, CURLOPT_URL, $url);
 6   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 7   curl_setopt($ch, CURLOPT_HEADER, 0);
 8   //執行並獲取HTML文檔內容
 9   $output = curl_exec($ch);
10   //釋放curl句柄
11   curl_close($ch);
12   return $output;
13 }

HTTPS請求時要注意SSL驗證

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();
  //設置選項,包括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驗證
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  //執行並獲取HTML文檔內容
  $output = curl_exec($ch);

  //釋放curl句柄
  curl_close($ch);
  return $output;
}


免責聲明!

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



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