The following script works on PHP 5.6.23
:
$options = [
CURLOPT_POST => 1,
CURLOPT_URL => 'https://uat.dwolla.com/oauth/rest/offsitegateway/checkouts',
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_POSTFIELDS => json_encode(['name'=>'value']),
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_CAINFO => '/path/to/certs/GoDaddyRootCertificateAuthority-G2.crt',
];
$ch = curl_init();
curl_setopt_array($ch, $options);
if( ! $result = curl_exec($ch)) $err = curl_error($ch);
else $err = null;
curl_close($ch);
if($err) echo $err;
else print_r(json_decode($result,true));
I get the expected response from Dwolla's payment API. To make my script more dynamic, I tried to change it to refer to the directory that hosts the certs I want cURL to trust. So I changed the last option (CURLOPT_CAINFO
) to:
CURLOPT_CAPATH => '/path/to/certs'
This breaks the script however and no connection is made; the error is:
SSL certificate problem: unable to get local issuer certificate
I know the directory is correct and the cert file is valid since the original script refers to the cert in that same directory. I expected cURL
to scan the files in the directory and find the cert it needs but this isn't happening. Why is this?
crt
totest.crt
and try again. – LatoyiaCURLOPT_CAINFO
). Same error the 2nd way (withCURLOPT_CAPATH
). – Leonidaleonidascurl.capath
(as well asopenssl.capath
) - both have no effect. But withopenssl.cainfo
it works. I'm not sure whycapath
doesn't work. – Straightout