Curl Get HTTPS request method
Doing a project today requires curl to get the third-party API, the other side's API is HTTPS mode.
Before using curl to get an HTTP request, but today gets an HTTPS request, the following error message appears: Certificate validation failed.
SSL certificate problem, verify the CA cert is OK. Details:error:14090086:ssl routines:SSL3_GET_SERVER_CERTIFICATE:certificate Verify failed
workaround , when curl requests, add
curl_setopt ($ch, Curlopt_ssl_verifypeer, false); Skip certificate Check curl_setopt ($ch, Curlopt_ssl_verifyhost, true); Check that the SSL encryption algorithm exists from the certificate
Curl HTTPS Request Code
<?php/** Curl Gets the HTTPS request * @param String $url The requested url* @param array $data the numbers to send * @param array $header header* @param int $timeout time-out when requested, default 30s*/function Curl_https ($url, $data =array (), $header =array (), $timeout =3 0) {$ch = Curl_init (); curl_setopt ($ch, Curlopt_ssl_verifypeer, false); Skip certificate Check curl_setopt ($ch, Curlopt_ssl_verifyhost, true); Check that the SSL encryption algorithm exists curl_setopt ($ch, Curlopt_url, $url) from the certificate; 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 the ' https://www.example.com/api/message.php '; $data = Array (' name ' = ' Fdipzone '); $header = Array (); $ Response = Curl_https ($url, $data, $header, 5); Echo $response;? >
This article explains how to get HTTPS request method through curl, more relevant content please focus on PHP Chinese web.
Related recommendations:
Upload images from PHP saved to the database for an example to explain
How to send and receive stream files via PHP
How to make a mosaic of pictures by PHP