Introduction: Following the previous "Analog login and acquisition of data", "Analog login with verification code site", we have a basic understanding of curl, this simple talk about the request HTTPS.
In many sites, such as TalkingData, Baidu and so on, some of the request agreement is to go SSL, plain English is HTTPS, this protocol in the simulation of curl may occur when the request is unsuccessful, and so on.
Let's talk about the solution.
This talk is simple, but it can explain the problem ....
Exception prompt
Most of the exception information is prompted as follows: certificate validation failed.
SSL certificate problem, verify the CA cert is OK. Details:error:14090086:ssl routines:SSL3_GET_SERVER_CERTIFICATE:certificate Verify failed
Cut into the topic
workaround , when curl requests, add
// Skip Certificate Check curl_setopt ($chfalse); // Check that the SSL encryption algorithm exists from the certificate curl_setopt ($chtrue);
Curl HTTPS POST request encapsulates code code
<?PHP/** Curl gets HTTPS request * @param String $url The requested url* @param array $data the number to be sent @param array $header request Sent header* @param int $timeout time-out, default 30s*/functionCurl_https ($url,$data=Array(),$header=Array(),$timeout=30){ $ch=Curl_init (); curl_setopt ($ch, Curlopt_ssl_verifypeer,false);//Skip Certificate Checkcurl_setopt ($ch, Curlopt_ssl_verifyhost,true);//Check that the SSL encryption algorithm exists from the certificatecurl_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;}//called$url= ' https://www.example.com/api/message.php ';$data=Array(' name ' = ' Fdipzone ');$header=Array();$response= Curl_https ($url,$data,$header, 5);Echo $response;?>
To be continued .....
This site article is for baby bus SD. Team Original, reproduced must be clearly noted: (the author's official website: Baby bus )
Reprinted from "Baby bus Superdo Team" original link: http://www.cnblogs.com/superdo/p/4792496.html
[PHP Automation-Advanced]003.CURL processing HTTPS request access