我使用的是 PHP 版本 8.1.2 和 Laravel 版本 9.8.1。我从这个https://www.scratchcode.io/curl-error-ssl-certificate-problem-unable-to-get-local-issuer-certificate/中了解了这些步骤解决此问题的链接。但我仍然遇到同样的错误。
我的代码
$response = Http::timeout(30)->get('http://example.com/users');
我还在 laravel 中做了另一个项目,但仍然遇到同样的错误
最佳答案
如何解决这个问题:
下载并解压cacert.pem按照 https://curl.se/docs/caextract.html 的说明进行操作
将其保存在文件系统的某个位置(例如,XAMPP 用户可能使用 C:\xampp\php\extras\ssl\cacert.pem)
在 php.ini 中,将此文件位置放入 [curl] 部分(将其放入 [openssl] 部分也是一个好主意):
示例:
[curl]
curl.cainfo = "C:\xampp\php\extras\ssl\cacert.pem"
[openssl]
openssl.cafile = "C:\xampp\php\extras\ssl\cacert.pem"
- 重新启动您的网络服务器(例如 Apache)和 PHP FPM 服务器(如果适用)
引用here
您还可以删除本地主机上的 SSL 验证。只需要在 'withOptions' 方法中向 de GuzzleHttp 客户端添加选项即可禁用验证。
$options = ['verify'=>false];
检查本地环境是否可以执行简单的 if:
public function authApi(){
$options = [];
if (App::environment('local')) {
$options = ['verify'=>false];
}
return Http::withBasicAuth($this->client_key, $this->client_key_secret)->withOptions($options);
}
关于php - 仍然显示相同的错误: cURL error 60: SSL certificate problem: unable to get local issuer certificate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71909552/