加入收藏 | 设为首页 | 会员中心 | 我要投稿 汽车网 (https://www.0577qiche.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php中curl get/post 例子 (包含https协议)

发布时间:2023-09-04 15:44:45 所属栏目:PHP教程 来源:
导读:php中curl函数可以实现get与post操作,我们经常使用它来做一些人为模仿操作了,下面我来简单的介绍post与get的例子.

get 方法,代码如下:

$url = "http://www.Cuoxin.com /index.php?a=b&c=d&e=f&g=".urlencode(&
php中curl函数可以实现get与post操作,我们经常使用它来做一些人为模仿操作了,下面我来简单的介绍post与get的例子.

get 方法,代码如下:

$url = "http://www.Cuoxin.com /index.php?a=b&c=d&e=f&g=".urlencode('王璐个人博客'); 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);    // 要求结果为字符串且输出到屏幕上 
curl_setopt($ch, CURLOPT_HEADER, 0); // 不要http header 加快效率 
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)'); 
curl_setopt($ch, CURLOPT_TIMEOUT, 15); 
$output = curl_exec($ch); 
curl_close($ch); 
var_dump($output); 
post 方法,代码如下:

$url = "http://www.Cuoxin.com/index.php"; 
$params = "a=b&c=d&e=f&g=" . urlencode('王璐个人博客'); 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // 要求结果为字符串且输出到屏幕上 
curl_setopt($ch, CURLOPT_HEADER, 0); // 不要http header 加快效率 
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)'); 
curl_setopt($ch, CURLOPT_TIMEOUT, 15); 
//开源代码Cuoxin.com 
curl_setopt($ch, CURLOPT_POST, 1);    // post 提交方式 
curl_setopt($ch, CURLOPT_POSTFIELDS, $params); 
 
$output = curl_exec($ch); 
curl_close($ch); 
var_dump($output); 
当请求https的数据时,会要求证书,这时候,加上下面这两个参数,规避ssl的证书检查,代码如下:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,FALSE);// https请求 不验证证书和hosts.

curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,FALSE);
 

(编辑:汽车网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章