gpt4 book ai didi

php - 带有 SSL 的 cURL 返回我验证位置

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

我尝试进行 cURL 身份验证,但 SSL 证书有问题。

我有这个代码:

$username = "123";
$password = "123";
$host = "https://api.shipnow.com.ar/users/authentication";

$headers = array(
'Content-Type:application/json',
'Authorization: Basic '. base64_encode("$username:$password") // <---
);

$process = curl_init($host);
curl_setopt($process, CURLOPT_HTTPHEADER, $headers);
curl_setopt($process, CURLOPT_HEADER, 1);
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_POST, 1);
curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($process, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($process, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($process, CURLOPT_CAINFO, '/cacert.pem');
curl_setopt($process, CURLOPT_CAPATH, '/cacert.pem');
$return = curl_exec($process);
$error = curl_error($process);
curl_close($process);

var_dump($error);

但是返回给我这个:

error setting certificate verify locations: CAfile: /cacert.pem CApath: /cacert.pem

我从这个链接下载 cacert.pem:

https://curl.haxx.se/docs/caextract.html

然后我将它放在我的项目文件夹中,在 index.php 旁边

谁知道怎么解决这个问题?

问候,

最佳答案

可能文件不存在。你能试试这段代码并检查文件吗?

$username = "123";
$password = "123";
$host = "https://api.shipnow.com.ar/users/authentication";

$headers = array(
'Content-Type:application/json',
'Authorization: Basic '. base64_encode("$username:$password") // <---
);

// Check File
if(!file_exists('/cacert.pem')) die('File not exists.');

$process = curl_init($host);
curl_setopt($process, CURLOPT_HTTPHEADER, $headers);
curl_setopt($process, CURLOPT_HEADER, 1);
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_POST, 1);
curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($process, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($process, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($process, CURLOPT_CAINFO, '/cacert.pem');
curl_setopt($process, CURLOPT_CAPATH, '/cacert.pem');
$return = curl_exec($process);
$error = curl_error($process);
curl_close($process);

var_dump($error);

关于php - 带有 SSL 的 cURL 返回我验证位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47535796/

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