Php curl: two methods for obtaining https requests
Php curl: two methods for obtaining https requests
This article mainly introduces two methods for php curl to obtain https requests. This article provides code instances that are set to not verify the certificate and host, and set a correct certificate, for more information, see
Today, a colleague reported an error when using curl to initiate an https request: "SSL certificate problem, verify that the CA cert is OK. details: error: 14090086: SSL routines: SSL3_GET_SERVER_CERTIFICATE: certificate verify failed"
Obviously, a problem occurs during certificate verification.
Curl can be used in the following two ways:
Method 1: Do not verify the certificate and host.
Before you execute 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 identification certificate is too old, resulting in incorrect Link error ssl certificate.
We need to download the new ssl local discriminant file.
Put it in the program file directory
Add the following configuration for curl
The Code is as follows:
Curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, true );;
Curl_setopt ($ ch, CURLOPT_CAINFO, dirname (_ FILE _). '/cacert. pem ');
Success
(My Verification Failed... Error message: SSL certificate problem, verify that the CA cert is OK. Details: error: 14090086: SSL routines: SSL3_GET_SERVER_CERTIFICATE: certificate verify failed)