我使用以下代码访问URL(URL使用https协议,并且具有有效证书)
// Initialize session and set URL.
$url = https://my url;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
// Set so curl_exec returns the result instead of outputting it.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Get the response and close the channel.
$response = curl_exec($ch);
curl_close($ch);
但我得到的输出是:
失败:错误号码:60。原因:SSL证书问题,请验证 CA证书没问题。详细信息:错误:14090086:SSL 例程:SSL3_GET_SERVER_CERTIFICATE:证书验证失败
有人可以指导我吗?
答案 0 :(得分:2)
使用'CURLOPT_RETURNTRANSFER'
$res = curl_init ('url');
curl_setopt($res,CURLOPT_RETURNTRANSFER,true);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$out = curl_exec($res);
curl_close($res);
echo $out;
了解更多信息,请阅读this
答案 1 :(得分:0)
尝试添加:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);