Home > Article > Backend Development > php curl 2 ways to get https requests, curlhttps_PHP tutorial
Today a colleague reported that when using curl to initiate an https request, an error was reported: "SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed”
Obviously, something went wrong while verifying the certificate.
If you want to use curl to initiate a normal https request, there are two ways:
Method 1: Set not to verify the certificate and host.
Before executing curl_exec(). Set option
Copy code The code is as follows:
$ch = curl_init();
......
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
Method 2: Set a correct certificate.
The local SSL certificate is too old, causing the link to report an incorrect SSL certificate.
We need to download the new ssl local identification file
http://curl.haxx.se/ca/cacert.pem
Put it in the program file directory
curl adds the following configuration
Copy code The code is as follows:
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,true); ;
curl_setopt($ch,CURLOPT_CAINFO,dirname(__FILE__).'/cacert.pem');
Done
(My verification failed... The error message is: SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed)
If you are interested in this, you can read the article of a great foreign god. http://unitstep.net/blog/2009/05/05/using-curl-in-php-to-access-https-ssltls-protected-sites/