Php uses curl to obtain https requests. phpcurl gets https. Php uses curl to obtain https requests. phpcurl obtains https. this example describes how php uses curl to obtain https requests. Share it with you for your reference. The specific analysis is as follows: php uses curl to obtain https requests. phpcurl obtains https
This example describes how php uses curl to obtain https requests. Share it with you for your reference. The specific analysis is as follows:
In a project today, curl is required to obtain a third-party API. the API of the other party is in https mode.
Previously, you can use curl to obtain an http request. However, when you obtain an https request today, the following error message is displayed: certificate verification failed.
SSL certificate problem, verify that the CA cert is OK. Details: error: 14090086: SSL routines: SSL3_GET_SERVER_CERTIFICATE: certificate verify failed
Solution: add the following content to the curl request:
The code is as follows:
Curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, false); // skip certificate check
Curl_setopt ($ ch, CURLOPT_SSL_VERIFYHOST, true); // check whether the SSL encryption algorithm exists from the certificate
Curl https request code
The code is as follows:
<? Php
/** Curl to obtain https requests
* @ Param String $ url request url
* @ Param Array $ number of data to be sent
* @ Param Array $ header the header sent during the request
* @ Param int $ timeout Time, 30 s by default
*/
Function curl_https ($ url, $ data = array (), $ header = array (), $ timeout = 30 ){
$ Ch = curl_init ();
Curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, false); // skip certificate check
Curl_setopt ($ ch, CURLOPT_SSL_VERIFYHOST, true); // check whether the SSL encryption algorithm exists from the certificate
Curl_setopt ($ ch, CURLOPT_URL, $ url );
Curl_setopt ($ ch, CURLOPT_HTTPHEADER, $ header );
Curl_setopt ($ ch, CURLOPT_POST, true );
Curl_setopt ($ ch, CURLOPT_POSTFIELDS, http_build_query ($ data ));
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, true );
Curl_setopt ($ ch, CURLOPT_TIMEOUT, $ timeout );
$ Response = curl_exec ($ ch );
If ($ error = curl_error ($ ch )){
Die ($ error );
}
Curl_close ($ ch );
Return $ response;
}
// Call
$ Url = 'https: // www.example.com/api/message.php ';
$ Data = array ('name' => 'fdipzone ');
$ Header = array ();
$ Response = curl_https ($ url, $ data, $ header, 5 );
Echo $ response;
?>
I hope this article will help you with php programming.
Examples in this article describes how php uses curl to obtain https requests. Share it with you for your reference. The specific analysis is as follows: today...