示例代码:
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://****.com"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_TIMEOUT, 15); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); echo $httpCode;
对应网站已经配置好SSL信息,但是这里无任何回传数据。
打印输出相关错误
print curl_error($ch);
示例代码部分变更为
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://****.com"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_TIMEOUT, 15); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); print curl_error($ch); curl_close($ch); echo $httpCode;
输出错误信息为
SSL certificate problem: unable to get local issuer certificate
1.如果你的内容不敏感,一个快捷的方法是使用curl_exec()之前跳过ssl检查项。
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
2.下载一个ca-bundle.crt ,放到对应的目录,在php.ini文件中配置下路径
https://github.com/bagder/ca-bundle/blob/e9175fec5d0c4d42de24ed6d84a06d504d5e5a09/ca-bundle.crt
在php.ini加入 ,重启web服务器