1 <?php 2 // +---------------------------------------------------------------------- 3 // | EBACERA [ WE CAN DO IT JUST THINK IT ] 4 // +---------------------------------------------------------------------- 5 // | Copyright (c) 2016 http://www.ebacera.com All rights reserved. 6 // +---------------------------------------------------------------------- 7 // | Author: 重设人生 <573914456@qq.com> 8 // +---------------------------------------------------------------------- 9 header("Content-type:text/html;charset=utf-8"); 10 //curl函数使用【分为post请求和get请求】 11 12 //==========post 请求========================= 13 $curl = 'http://www.studyweb.com/example/LAMP_PHP/curl/demo.php'; 14 //1、初始化 15 $ch=curl_init(); 16 //2、设置url 17 curl_setopt($ch,CURLOPT_URL,$curl); 18 //3、不直接显示,返回一个字符串 19 curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); 20 //4、服务器端的证书不验证 21 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 22 //5、客户端证书不验证 23 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 24 //6、设置提交方式为post 25 curl_setopt($ch,CURLOPT_POST,true); 26 //数据 27 $data ="type=12345"; 28 //7、设置提交的数据 29 curl_setopt($ch,CURLOPT_POSTFIELDS,$data); 30 //8、执行访问 31 $str=curl_exec($ch); 32 //9、关闭curl释放资源 33 curl_close($ch); 34 35 echo $str; 36 37 38 39 40 //==========post 请求========================= 41 //url 42 $curl = 'http://www.studyweb.com/example/LAMP_PHP/curl/demo.php'; 43 //url参数数组 44 $data=array('type'=>'123456'); 45 //url参数拼接 46 $curl .="?".http_build_query($data); 47 //1、初始化 48 $ch=curl_init(); 49 //2、设置url 50 curl_setopt($ch,CURLOPT_URL,$curl); 51 //2、设置url 52 curl_setopt($ch,CURLOPT_URL,$curl); 53 //3、不直接显示,返回一个字符串 54 curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); 55 //4、服务器端的证书不验证 56 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 57 //5、客户端证书不验证 58 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 59 $str=curl_exec($ch); 60 curl_close($ch); 61 echo $str; 62 63 64 65 66 67 68 69 70 71 //获取access_token 1、 72 function _request($curl, $https = true, $method = 'get', $data = null) 73 { 74 75 $ch = curl_init(); 76 curl_setopt($ch, CURLOPT_URL, $curl); //设置URL 77 curl_setopt($ch, CURLOPT_HEADER, false);//不返回网页URL的头信息 78 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //不直接显示,返回一个字符串 79 if ($https) { 80 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);//服务器端的证书不验证 81 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);//客户端证书不验证 82 } 83 if ($method == 'post') { 84 curl_setopt($ch, CURLOPT_POST, true); //设置为POST提交方式 85 curl_setopt($ch, CURLOPT_POSTFIELDS, $data);//设置提交数据$data 86 } 87 $str = curl_exec($ch);//执行访问 88 curl_close($ch);//关闭curl释放资源 89 return $str; 90 } 91 ?>