php post请求https
<?php $url = 'https://www.xxx.com'; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HEADER, 1); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);//这个是重点。 $data = curl_exec($curl); curl_close($curl); var_dump($data);
注意
当请求https的数据时,会要求证书,这时候,加上下面这两个参数,规避ssl的证书检查
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // https请求 不验证证书和hosts
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);