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

王林
Release: 2023-04-08 07:52:02
forward
3555 people have browsed it

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;
}
Copy after login

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;
}
Copy after login

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!

Related labels:
source:jb51.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template