Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
cURL SSL无法在Xampp上获取本地颁发者证书_Curl_Ssl - Fatal编程技术网

cURL SSL无法在Xampp上获取本地颁发者证书

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

我已经为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 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托管的用户。下面是一个场景

  • 网站由谷歌计算引擎(GCE)托管
  • 证书由戈达迪颁发
  • 每当我尝试调用从外部服务器到GCE上的应用程序的CURL时,我都会得到一个错误——无法获取本地颁发者证书

    我是如何解决这个问题的,通过使用GoDaddy提供的证书包,使用以下代码调用我的cURL。本质上,网络上可用的大多数捆绑包都没有GoDaddy证书颁发机构,因此会出现错误。如果使用GoDaddy提供的证书捆绑包,则不会出现错误

    如果您正在寻找GoDaddy证书捆绑包,它可以在您的GoDaddy帐户的SSL/TSL部分中找到

    $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托管的用户。下面是一个场景

  • 网站由谷歌计算引擎(GCE)托管
  • 证书由戈达迪颁发
  • 每当我尝试调用从外部服务器到GCE上的应用程序的CURL时,我都会得到一个错误——无法获取本地颁发者证书

    我是如何解决这个问题的,通过使用GoDaddy提供的证书包,使用以下代码调用我的cURL。本质上,网络上可用的大多数捆绑包都没有GoDaddy证书颁发机构,因此会出现错误。如果使用GoDaddy提供的证书捆绑包,则不会出现错误

    如果您正在寻找GoDaddy证书捆绑包,它可以在您的GoDaddy帐户的SSL/TSL部分中找到

    $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时获得此反馈很好。我改进了我的答案,以便提供较少的外部链接。请在此处找到答案。这是有效的解决方案,请在这里找到答案。这是有效的解决方案