php - CURL api call with certificate fileGet the solution ↓↓↓
Got from my API providor only .crt file (without private key), i change the name to .pem:
-----BEGIN CERTIFICATE----- content -----ENDCERTIFICATE-----
Trying to make an PAI call with a .pem file like this:
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); curl_setopt($ch, CURLOPT_HTTPHEADER, array("content-type: text/xml")); curl_setopt($ch, CURLOPT_VERBOSE, '1'); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, '2'); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, '1'); curl_setopt($ch, CURLOPT_SSLCERT, PATH.'/file.pem');
i got this error:
[curl_error_58] => unable to set private key file: 'file.pem' type PEM
my solution was:
i ask from my API provider if they have a private key, and they generate one for me, so the error is very simple i actually needed this private key, without this key "CURLOPT_SSLCERT" just not work.
curl_setopt($ch, CURLOPT_SSLKEY, PATH.'/file.key'); curl_setopt($ch, CURLOPT_SSLKEYPASSWD, '000');
Share solution ↓
Link To Answer People are also looking for solutions of the problem: call to undefined function str_contains()
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.