cURL SSL无法在Xampp上获取本地颁发者证书
我已经为windows安装了一个新的XAMPP1.8.3版本,它支持cURL。我正在尝试连接的测试站点是。这是我的密码:cURL SSL无法在Xampp上获取本地颁发者证书,curl,ssl,Curl,Ssl,我已经为windows安装了一个新的XAMPP1.8.3版本,它支持cURL。我正在尝试连接的测试站点是。这是我的密码: <?php // Set the URL to visit $url = "https://www.mozilla.org/en-US/"; // Set .pem file to use $certFile = dirname(__FILE__) . '\www.mozilla.org.crt'; // In this example we are referr
<?php
// Set the URL to visit
$url = "https://www.mozilla.org/en-US/";
// Set .pem file to use
$certFile = dirname(__FILE__) . '\www.mozilla.org.crt';
// In this example we are referring to a page that handles xml
$headers = array( "Content-Type: text/xml",);
// Initialise Curl
$curl = curl_init($url);
if ($curl === false)
throw new Exception(' cURL init failed');
// Set up to view correct page type
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
// Turn on SSL certificate verfication
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, TRUE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($curl, CURLOPT_CAPATH, $certFile);
// Tell the curl instance to talk to the server using HTTP POST
curl_setopt($curl, CURLOPT_POST, 1);
// 1 second for a connection timeout with curl
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5);
// Try using this instead of the php set_time_limit function call
curl_setopt($curl, CURLOPT_TIMEOUT, 60);
// Causes curl to return the result on success which should help us avoid using the writeback option
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
echo "Connecting to " . $url . "<br/>";
echo "Using " . $certFile . "<br/>";
echo "<br/>";
if(curl_exec($curl) == false)
echo ("Error: " . curl_errno($curl) . ", " . curl_error($curl) . "<br/>");
else
echo "Success!" . "<br/>";
?>
我有一个远方的朋友从他的机器上用.pem文件尝试了这个代码,结果他成功了。我的运行时环境中是否缺少一些东西可以阻止这种情况?谢谢。尝试使用最新的“来自Mozilla的证书数据”捆绑包
似乎它包含了大多数常见的CA
在php.ini中设置
curl.cainfo=<path-to>cacert.pem
请确保curl.cainfo设置正确。尝试使用最新的“来自Mozilla的证书数据”捆绑包
似乎它包含了大多数常见的CA
在php.ini中设置
curl.cainfo=<path-to>cacert.pem
您的curl.cainfo设置正确。我将此答案留给像我这样使用GoDaddy托管的用户。下面是一个场景
$ch = curl_init("https://my.secure.website");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
curl_setopt($ch, CURLOPT_CAINFO, "/path/to/gd_bundle-g2-g1.crt");
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
我把这个答案留给像我这样使用GoDaddy托管的用户。下面是一个场景
$ch = curl_init("https://my.secure.website");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
curl_setopt($ch, CURLOPT_CAINFO, "/path/to/gd_bundle-g2-g1.crt");
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
虽然此链接可以回答问题,但最好在此处包含答案的基本部分,并提供链接供参考。如果链接页面更改,则仅链接的答案可能无效感谢您的评论@Moes在开始使用StackOverflow时获得此反馈是很好的。我改进了我的答案,以便提供较少的外部链接。虽然此链接可以回答问题,最好在这里包括答案的基本部分,并提供链接供参考。如果链接页面更改,则仅链接答案可能无效感谢您的评论@Moes在开始使用StackOverflow时获得此反馈很好。我改进了我的答案,以便提供较少的外部链接。请在此处找到答案。这是有效的解决方案,请在这里找到答案。这是有效的解决方案