gpt4 book ai didi

PHP curl 错误 : SSL certificate problem: unable to get local issuer certificate

转载 作者:太空宇宙 更新时间:2023-11-03 14:26:07 25 4
gpt4 key购买 nike

我查看了 STACKOVERFLOW 上列出的每个解决方案。没有什么能解决这个问题。我遇到的问题仅在我将端口(在此示例中为 5443)附加到 cURL PHP 代码时出现。如果我在没有端口的情况下执行 CLI,它就可以工作。在代码中,如果我只做一个直接的 URL https://HOSTNAME/api/test无需分配端口,它就可以工作。无论哪种方式,我都可以看到 GET 进来。这都是关于认证验证的。该端口在服务器上打开。

我有 GoDaddy G2 证书。我有一个带有 CA bundle 的新建服务器,我尝试使用根证书,来自

的证书 bundle
"https://curl.haxx.se/docs/caextract.html"

以及所有其他组合。添加端口号时总是出现相同的错误:

“SSL 证书问题:无法获取本地颁发者证书”

$url = "https://HOSTNAME/api/test";
$curl = curl_init();

if ($curl === false)
{
echo "Failure";

} else
{

curl_setopt($curl, CURLOPT_PORT, 5443);
curl_setopt($curl, CURLOPT_HTTPGET, true);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($curl, CURLOPT_TIMEOUT, 60);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);


// Turn on SSL certificate verification
curl_setopt($curl, CURLOPT_CAPATH, "/fully_resolved_path/");

// and tried this way too

curl_setopt($curl, CURLOPT_CAPATH, "/fully_resolved_path");

//试过了

curl_setopt($curl,CURLOPT_CAINFO,"/fully_resolved_path/cacert.pem"); 

//这实际上是默认设置,不再支持1,对本例的最终结果没有影响。

curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);

//为 TRUE 时失败! FALSE 时不执行检查

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, TRUE);


$result = curl_exec($curl);

if ($result === false)
{
echo curl_error($curl);

} else

{
echo $result;
}

curl_close($curl);

一切都已设置并按预期工作,返回一个 JSON 对象。只有当我添加端口号时,它才会阻塞。 SSL 证书中的通用名称与 HOSTNAME 匹配。如前所述,在我添加端口号之前它一直有效。

最佳答案

I have looked at every solution listed on STACKOVERFLOW. Nothing resolves this issue.

哇。但不幸的是,这个“信息”是无用的,因为它没有说明您实际尝试过的任何内容。

The issue I am having is only when I attach a port, in this example 5443, to the cURL PHP code. If I do a CLI without the port it works.

这是因为如果没有端口,它将使用端口 443。由于您显式使用端口 5443,您连接到具有不同设置的不同服务器,并且与端口 443 上的证书相比,它提供不同的证书。只需尝试将端口显式设置为443,您会发现它有效。

很可能端口 5443 上的服务器正在提供一些自签名证书、一些由某个未知 CA 颁发的证书或缺少必要的链证书(即配置错误)。这些是通常与此类错误相关的原因,您应该已经看到了这一点并且还看到了解决方案,因为您“查看了 STACKOVERFLOW 上列出的每个解决方案”。请记住,要修复您需要查看端口 5443 的服务器而不是端口 443 的默认服务器。

关于PHP curl 错误 : SSL certificate problem: unable to get local issuer certificate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57049205/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com