1. Curl requests the HTTPS protocol interface in Get mode
// Note: The address here has a parameter, without parameters you handle it yourself oh get is simple
functionCurl_get_https ($url){ $curl= Curl_init ();//start a Curl sessioncurl_setopt ($curl, Curlopt_url,$url); curl_setopt ($curl, Curlopt_header, 0); curl_setopt ($curl, Curlopt_returntransfer, 1); curl_setopt ($curl, Curlopt_ssl_verifypeer,false);//Skip Certificate Checkcurl_setopt ($curl, Curlopt_ssl_verifyhost,true);//Check that the SSL encryption algorithm exists from the certificate $tmpInfo= Curl_exec ($curl);//returns the JSON object for the API//close URL requestCurl_close ($curl); return $tmpInfo;//returns a JSON object}
2. Curl requests the HTTPS protocol interface in post mode
/*PHP CURL HTTPS POST*/functionCurl_post_https ($url,$data){//Analog commit data function $curl= Curl_init ();//start a Curl sessioncurl_setopt ($curl, Curlopt_url,$url);//the address to be accessedcurl_setopt ($curl, Curlopt_ssl_verifypeer, 0);//examination of the source of the certification certificatecurl_setopt ($curl, Curlopt_ssl_verifyhost, 1);//Check that the SSL encryption algorithm exists from the certificatecurl_setopt ($curl, Curlopt_useragent,$_server[' http_user_agent ']);//simulating the browser used by the usercurl_setopt ($curl, curlopt_followlocation, 1);//Use Auto Jumpcurl_setopt ($curl, Curlopt_autoreferer, 1);//set Referer automaticallycurl_setopt ($curl, Curlopt_post, 1);//send a regular POST requestcurl_setopt ($curl, Curlopt_postfields,$data);//Post-submitted packetscurl_setopt ($curl, Curlopt_timeout, 30);//setting a timeout limit to prevent a dead loopcurl_setopt ($curl, Curlopt_header, 0);//Displays the contents of the header area returnedcurl_setopt ($curl, Curlopt_returntransfer, 1);//gets the information returned as a file stream $tmpInfo= Curl_exec ($curl);//Perform Actions 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:curl request HTTPS protocol API with Get and post respectively