Convert curl-command to php curl

与世无争的帅哥 提交于 2019-12-12 11:43:21

问题


Im trying to convert a curl-statement with an authentication header to a php curl request. But it doesn't seem to be working, because I receive the error below with 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);

Does anyone sees my fault?


回答1:


cURL is not able to verify the authenticity of the certificate being used, because the certificate for the signing authority cannot be found in the local database.

This might be symptomatic of a self signed certificate being used.

What you should do is add the certificate for the signing authority to /etc/ssl/certs/ca-certificates.crt.

What you can do is use curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);, which will disable the check that is failing.

You really should use the first option.



来源:https://stackoverflow.com/questions/35314689/convert-curl-command-to-php-curl

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!