如何在Mac OS X上为PHP CURL调用指定当前证书?

时间:2017-06-15 23:16:46

标签: php macos curl certificate ssl-certificate

我从https://curl.haxx.se/docs/caextract.html下载了证书,并指定了CURLOPT_CAINFO文件的完整路径

我一直收到错误 - 卷曲错误:SSL:证书验证失败(结果:5)

我使用的是Mac OS Sierra,10.12和PHP 7.0.11

我从哪里获得有效证书才能进行SSL API调用?

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_TIMEOUT, 30); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt ($ch, CURLOPT_CAINFO, "cacert.pem");
$result=curl_exec ($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);  

0 个答案:

没有答案