0

I am trying to fetch data from rest api(https) using curl. I have downloaded cacert.pem from http://curl.haxx.se/docs/caextract.html and moved into project root directory. Here is my code but it's not working. Can anyone help me?

$curl = curl_init();

// Set some options
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLINFO_HEADER_OUT, true);

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, true);
curl_setopt($curl, CURLOPT_CAINFO, __DIR__.DIRECTORY_SEPARATOR.'cacert.pem');
curl_setopt($curl, CURLOPT_URL, 'https://startupgenome.com/api/2/boulder-co');

// Send the request & save response to $resp
$resp = curl_exec($curl);
curl_close($curl);
print_r($resp);
1
  • 3
    Define "not working". What is the expected behavior and what is happening instead? Do you get an error? Commented Apr 26, 2015 at 14:51

1 Answer 1

2

There are some problems. If you open your API url https://startupgenome.co/api/2/boulder-co you can see that the certificate is not valid. If you accept them you get an 404 (Well this doesn't seem right.).

So i think you should first insert the correct URL.

The second is. If the certificate is not valid on the server side you can't verify the host and your cacert.pem make no sense if the destination has no valid certificate.

If you really want to access that page then disable the checks but don't forget to enable that on production mode.

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.