PHP开发实例大全(提高卷) 中文完整pdf扫描版[244MB]
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2016/6/23
- * Time: 12:39
- */
- function curlPost($url, $data = array(), $timeout = 30, $CA = true){
- $cacert = getcwd() . '/cacert.pem'; //CA根证书
- $SSL = substr($url, 0, 8) == "https://" ? true : false;
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout-2);
- if ($SSL && $CA) {
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); // 只信任CA颁布的证书
- curl_setopt($ch, CURLOPT_CAINFO, $cacert); // CA根证书(用来验证的网站证书是否是CA颁布)
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); // 检查证书中是否设置域名,并且是否与提供的主机名匹配
- } else if ($SSL && !$CA) {
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 信任任何证书
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1); // 检查证书中是否设置域名
- }
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')); //避免data数据过长问题
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
- //curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); //data with URLEncode
- $ret = curl_exec($ch);
- // var_dump(curl_error($ch)); //查看报错信息
- curl_close($ch);
- return $ret;
- }
- $subject = curlPost('https://app.kuitao8.com/index.php');
- print_r($subject);
证书下载
http://img.kuitao8.com/uploads/2014/0601/20140601044614237.rar
参考地址
http://www.kuitao8.com/20140601/2583.shtml
转载请注明:谷谷点程序 » php curl采集https