gpt4 book ai didi

php - 无法在“file_get_contents()”中加载cafile流?

转载 作者:行者123 更新时间:2023-12-03 20:31:11 27 4
gpt4 key购买 nike

我正在尝试从Google地理编码API获取JSON数据。但是,PHP警告显示有关“加载cafile流失败”的一些错误

这是我的代码:

$apiKey  = 'apikey';
$address = urlencode( '1600 Amphitheatre Pkwy, Mountain View, CA 94043'
);
$url = "https://maps.googleapis.com/maps/api/geocode/json?address=
{$address}key={apiKey}";
$resp = json_decode( file_get_contents( $url ), true );
echo $url;

$lat = $resp['results'][0]['geometry']['location']['lat'] ?? '';
$long = $resp['results'][0]['geometry']['location']['lng'] ?? '';


这是错误:

PHP Warning:  failed loading cafile stream: `C:\xampp\apache\bin\curl-ca- 
bundle.crt' in C:\Users\1\Desktop\test.php on line 7

Warning: failed loading cafile stream: `C:\xampp\apache\bin\curl-ca-
bundle.crt' in C:\Users\1\Desktop\test.php on line 7
PHP Warning: file_get_contents(): Failed to enable crypto in
C:\Users\1\Desktop\test.php on line 7

Warning: file_get_contents(): Failed to enable crypto in
C:\Users\1\Desktop\test.php on line 7
PHP Warning:
file_get_contents(https://maps.googleapis.com/maps/api/geocode/json?
address=1600+Amphitheatre+Pkwy%2C+Mountain+Vi
ew%2C+CA+94043key={apiKey}): failed to open stream: operation failed in
C:\Users\1\Desktop\test.php on line 7

Warning:
file_get_contents(https://maps.googleapis.com/maps/api/geocode/json?
address=1600+Amphitheatre+Pkwy%2C+Mountain+View%2C
+CA+94043key={apiKey}): failed to open stream: operation failed in
C:\Users\1\Desktop\test.php on line 7
https://maps.googleapis.com/maps/api/geocode/json?
address=1600+Amphitheatre+Pkwy%2C+Mountain+View%2C+CA+94043key={apiKey}

最佳答案

当您的php.ini文件的curl.cainfo和openssl.cafile配置属性未针对任何允许您与ssl创建连接的有效证书时,就会发生此错误,因为它们将无效。

例如,使用CURL调用外部服务器的请求时,就会发生这种情况。

您必须从链接here中下载casert.pem。

并将认证文件放在路径中:


C:\ xampp \ apache \ bin \ cacert.pem


之后,在名为:curl.cainfo和openssl.cafile的配置项上检查php.ini并进行此配置

例如:

curl.cainfo = "C:\xampp\apache\bin\cacert.pem"
openssl.cafile = "‪C:\xampp\apache\bin\cacert.pem"

关于php - 无法在“file_get_contents()”中加载cafile流?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55526568/

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