1. Post request
Parameter 1: Request address
Parameter 2: parameter in array form
/** * @param string $url POST request address * @param array $params * @return mixed*/functionCurl_post ($url,Array $params=Array()){ $data _string= Json_encode ($params); $ch=Curl_init (); curl_setopt ($ch, Curlopt_url,$url); curl_setopt ($ch, Curlopt_header, 0); curl_setopt ($ch, Curlopt_returntransfer, 1); curl_setopt ($ch, Curlopt_connecttimeout, 10); curl_setopt ($ch, Curlopt_post, 1); curl_setopt ($ch, Curlopt_ssl_verifypeer,false); curl_setopt ($ch, Curlopt_postfields,$data _string); curl_setopt ($ch, Curlopt_httpheader,Array( ' Content-type:application/json ' ) ); $data= Curl_exec ($ch); Curl_close ($ch); return($data);}
2. Get request
/** * @param string $url GET request address * @param int $httpCode return status code * @return Mixed*/functionCurl_get ($url, &$httpCode= 0){ $ch=Curl_init (); curl_setopt ($ch, Curlopt_url,$url); curl_setopt ($ch, Curlopt_returntransfer, 1); //Do not do certificate verification, deploy in Linux environment please change to truecurl_setopt ($ch, Curlopt_ssl_verifypeer,false); curl_setopt ($ch, Curlopt_connecttimeout, 10); $file _contents= Curl_exec ($ch); $httpCode= Curl_getinfo ($ch,Curlinfo_http_code); Curl_close ($ch); return $file _contents;}
< records > Curl Package functions