使用curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
来忽略证书
<?php
//php提交post表单
function testAction($url,$post_data){
$o = "";
foreach ( $post_data as $k => $v )
{
$o.= "$k=" . urlencode( $v ). "&" ;
}
$post_data = substr($o,0,-1);
$ch = curl_init();//初始化curl
curl_setopt($ch, CURLOPT_URL,$url);//抓取指定网页
curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); //不验证证书
$data = curl_exec($ch);//运行curl
curl_close($ch);
return $data;
}
$url = 'http://localhost/login.php';
$post_data['user']= 'admin';
$post_data['pass']= 'admin';
echo testAction($url,$post_data);