使用PHP CURL的SSL证书
我正在使用curl通过https向rightmove API发送一个xml文件——他们向我提供了所有证书 我得到一个错误: 60SSL证书问题:无法获取本地颁发者 认证结果= 我已经尝试了在其他类似stackoverflow帖子上找到的所有东西,但没有任何效果,我尝试下载了旧的cacert.pem并更改了php.ini中的文件-我安装了我的个人信息文件并在浏览器和本地机器上创建了证书,没有任何东西可以消除错误 这是我的PHP:使用PHP CURL的SSL证书,php,xml,ssl,curl,Php,Xml,Ssl,Curl,我正在使用curl通过https向rightmove API发送一个xml文件——他们向我提供了所有证书 我得到一个错误: 60SSL证书问题:无法获取本地颁发者 认证结果= 我已经尝试了在其他类似stackoverflow帖子上找到的所有东西,但没有任何效果,我尝试下载了旧的cacert.pem并更改了php.ini中的文件-我安装了我的个人信息文件并在浏览器和本地机器上创建了证书,没有任何东西可以消除错误 这是我的PHP: <?php $xml = file_get_content
<?php
$xml = file_get_contents("myxml.xml");
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt ($ch, CURLOPT_CAINFO, dirname(__FILE__).'\mypem.pem');
curl_setopt($ch, CURLOPT_URL, "https://adfapi.adftest.rightmove.com/v1/property/sendpropertydetails");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_REFERER, 'https://adfapi.adftest.rightmove.com/v1/property/sendpropertydetails');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_VERBOSE , 1);
$ch_result = curl_exec($ch);
print curl_errno($ch);
print curl_error($ch);
echo "Result = ".$ch_result;
curl_close($ch);
?>
这让我头痛了好几天,如果有任何帮助,我将不胜感激。它失败了,因为curl无法验证服务器提供的证书 有两个选项可以让它工作: 1允许curl建立不安全的连接,即curl不验证证书
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
2在php.ini中添加根CA(签署服务器证书的CA)
curl.cainfo=/path/to/cacert.pem
您应该使用选项2,因为这是确保连接到安全ftp服务器的选项。对于我的特殊情况,我需要添加密钥文件、sslcert和证书密码
//$xml = file_get_contents("thexmlfile.xml");
$xml= $propertyXml->asXML();
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CAINFO, getcwd() . '\pemfile.pem');
curl_setopt($ch, CURLOPT_URL, "https://adfapi.adftest.rightmove.com/v1/property/sendpropertydetails");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSH_PRIVATE_KEYFILE, getcwd() . '\myjks.jks');
curl_setopt($ch, CURLOPT_SSLCERT, getcwd() . '\pemfile.pem');
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, "thesslpassword");
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_REFERER, "https://adfapi.adftest.rightmove.com/v1/property/sendpropertydetails");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_VERBOSE , 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$ch_result = curl_exec($ch);
print curl_errno($ch);
print curl_error($ch);
echo "Result = ".$ch_result;
curl_close($ch);
我在HTTP访问远程https站点时遇到了相同的“SSL证书问题:无法获取本地颁发者证书结果”错误。我只需要向php curl提供CA证书,即CURLOPT_CAINFO:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CAINFO, "/path/to/CA_Bundle.crt");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$output = curl_exec($ch);
if (curl_errno($ch)) {
$error_msg = curl_error($ch);
print "curl_error: $error_msg <br>";
} else {
print "output: $output<br>";
}
curl_close($ch);
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$URL);
curl_setopt($ch,CURLOPT_CAINFO,“/path/to/CA_Bundle.crt”);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
$output=curl\u exec($ch);
if(旋度误差($ch)){
$error\u msg=curl\u error($ch);
打印“卷曲错误:$error\u msg
”;
}否则{
打印“输出:$output
”;
}
卷曲关闭($ch);
尝试设置curl\u setopt($ch,CURLOPT\u SSL\u VERIFYPEER,false);并移除curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,2)@Indrajit感谢Indrajit,但是api需要身份验证。假设您的浏览器中没有出现相同的错误。您的修补程序不是最新的,或者您安装的PHP版本没有为您的平台正确配置。我在本地、我的web服务器和我的工作服务器上收到此错误。@symcbean,但您是正确的,我可以在浏览器中导航没有问题。经过一整天的尝试,我仍然无法解决这个问题。我厌倦了使用cacert.pem的选项2(我从其他帖子在互联网上找到了多个选项)当然,如果我在更改curl.cainfo时尝试不验证主机,api将返回auth失败。我得到:60SSL证书问题:无法获取本地颁发者证书结果=@GazSmith检查此链接谢谢@walkingRed,虽然rightmoves api仍然存在身份验证问题,所以证书肯定是错误的。请粘贴整个curl请求。我也在为Rightmove的Curl请求挣扎了几天。谢谢,这对我一直都有帮助