1. Curl requests the HTTPS protocol interface in Get mode
1 functionCurl_get_https ($url){2 $curl= Curl_init ();//start a Curl session3curl_setopt ($curl, Curlopt_url,$url);4curl_setopt ($curl, Curlopt_header, 0);5curl_setopt ($curl, Curlopt_returntransfer, 1);6curl_setopt ($curl, Curlopt_ssl_verifypeer,false);//Skip Certificate Check7curl_setopt ($curl, Curlopt_ssl_verifyhost,true);//Check that the SSL encryption algorithm exists from the certificate8 $tmpInfo= Curl_exec ($curl);//returns the JSON object for the API9 //Close URL requestTenCurl_close ($curl); One return $tmpInfo;//returns a JSON object A}
2. Curl requests the HTTPS protocol interface in post mode
1 functionCurl_post_https ($url,$data){//Analog commit data function2 $curl= Curl_init ();//start a Curl session3curl_setopt ($curl, Curlopt_url,$url);//the address to be accessed4curl_setopt ($curl, Curlopt_ssl_verifypeer, 0);//examination of the source of the certification certificate5curl_setopt ($curl, Curlopt_ssl_verifyhost, 1);//Check that the SSL encryption algorithm exists from the certificate6curl_setopt ($curl, Curlopt_useragent,$_server[' http_user_agent ']);//simulating the browser used by the user7curl_setopt ($curl, curlopt_followlocation, 1);//Use Auto Jump8curl_setopt ($curl, Curlopt_autoreferer, 1);//set Referer automatically9curl_setopt ($curl, Curlopt_post, 1);//send a regular POST requestTencurl_setopt ($curl, Curlopt_postfields,$data);//Post-submitted packets Onecurl_setopt ($curl, Curlopt_timeout, 30);//setting a timeout limit to prevent a dead loop Acurl_setopt ($curl, Curlopt_header, 0);//Displays the contents of the header area returned -curl_setopt ($curl, Curlopt_returntransfer, 1);//gets the information returned as a file stream - $tmpInfo= Curl_exec ($curl);//Perform Actions the if(Curl_errno ($curl)) { - Echo' Errno '. Curl_error ($curl);//Catch-catching anomaly - } -Curl_close ($curl);//turn off the curl session + return $tmpInfo;//return data, JSON format -}
PHP function Curl Requests the HTTPS protocol interface API in the form of Get and post respectively