php curl 2 ways to get https requests
This article mainly introduces two methods for php curl to obtain https requests. This article gives code examples of two common practices: not verifying the certificate and host, and setting a correct certificate. Friends who need it can refer to it. Next
Today a colleague reported that when using curl to initiate an https request, an error occurred: "SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed"
Obviously, there was a problem when 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
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
Place it in the program file directory
curl Add the following configuration
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)