Curl is used to obtain the https request method, curlhttps
Curl
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, Added to the curl request
Curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, false); // skip the certificate check curl_setopt ($ ch, CURLOPT_SSL_VERIFYHOST, true); // check from the certificate whether the SSL encryption algorithm exists
Curl https Request Code
<? Php/** curl Get https Request * @ param String $ url request url * @ param Array $ header sent during the request * @ param int $ timeout time, 30 s by default */function curl_https ($ url, $ header = array (), $ timeout = 30) {$ ch = curl_init (); curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, false); // skip the certificate check curl_setopt ($ ch, CURLOPT_SSL_VERIFYHOST, true); // check from the certificate whether the SSL encryption algorithm has curl_setopt ($ ch, CURLOPT_URL, $ url ); curl_setopt ($ ch, CURLOPT_HTTPHEADER, $ hea Der); curl_setopt ($ ch, CURLOPT_POST, true); curl_setopt ($ ch, CURLOPT_POSTFIELDS, ''); 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'response response Header = array ('content-type: application/json'); $ response = Curl_https ($ url, $ header, 5); echo $ response;?>
Curl https
Save the url by using session or other methods on the page of the callback address. You can call it on the curl page.
Php uses curl to obtain the https address
You even
Neither comment 1 nor comment 2 can output data.
Because it outputs your data by default.
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); // The output content is a string
Add the above sentence.
In this way, no data is output.