Home >Backend Development >PHP Tutorial >Analysis of parameter passing issues when using curl to send get requests in PHP

Analysis of parameter passing issues when using curl to send get requests in PHP

王林
王林forward
2020-01-07 17:56:403562browse

Analysis of parameter passing issues when using curl to send get requests in PHP

get request is the simplest request, but you should pay attention to whether your request is an http request or an https request, because SSL verification must be turned off when making an https request, otherwise the verification will not pass and there is no way. Data is requested.

Parameters of GET request

Get passes parameters in the same way as normal request url passes parameters

(Free online video tutorial sharing: php video tutorial)

function get_info($card){
 
  $url ="http://www.sdt.com/api/White/CardInfo?cardNo=".$bank_card; 
 
  $ch = curl_init();
  //设置选项,包括URL
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_HEADER, 0);
 
  //执行并获取HTML文档内容
  $output = curl_exec($ch);
  //释放curl句柄
  curl_close($ch);
  return $output;
}

Pay attention to SSL verification when making HTTPS requests

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;
}

Related article tutorial recommendations:php tutorial

The above is the detailed content of Analysis of parameter passing issues when using curl to send get requests in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:jb51.net. If there is any infringement, please contact admin@php.cn delete