Convert curl command to php curl

I am trying to convert a curl-statement with an authentication header into a php curl request. But it doesn't seem to work because I get the following error echo 'error:' . curl_error($ch);::

error:SSL certificate problem: unable to get local issuer certificate

My curl command looks like this:

curl --user XXXX:YYYY "URL"

My php-curl looks like this:

$login = 'XXXX';
$password = 'YYYY';
$url = 'URL';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HEADER, true); 
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "$login:$password");
echo curl_exec($ch);
$result = curl_exec($ch);

if ($result != false){
        echo "SUCCESS";
}else{
        echo "<br>";
        echo 'error:' . curl_error($ch);
        echo "<br>";
    }
curl_close($ch);  
echo($result);

Anyone see my mistake?

+4
source share
1 answer

cURL cannot verify the authenticity of the certificate used because the certificate for signing authority cannot be found in the local database.

This may be a symptom of using a self-signed certificate.

What you have to do is add a certificate for the subscription authority to /etc/ssl/certs/ca-certificates.crt.

, curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);, , .

.

+3

Source: https://habr.com/ru/post/1628110/


All Articles