/** * @Description: curl request * @Author: Yang * @Param $ url * @param null $data * @param string $method * @param array $header * @param bool $https * @param int $timeout * @return mixed */ function curl_request($url, $data=null, $method='get', $header = array("content-type: application/json"), $https=true, $timeout = 5){ $method = strtoupper($method); $ch = curl_init();//初始化 curl_setopt($ch, CURLOPT_URL, $url);//访问的URL curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // get only page content, but does not output IF ( $ HTTPS ) { curl_setopt ( $ CH , CURLOPT_SSL_VERIFYPEER, to false ); // HTTPS request does not verify the certificate curl_setopt ( $ CH , CURLOPT_SSL_VERIFYHOST, to false ); // HTTPS request does not verify the HOST } IF ( $ Method ! = "the GET" ) { IF ( $ Method == 'the POST' ) { curl_setopt ( $ CH , CURLOPT_POST, to true ); // request type as post request } IF ( $ Method == 'the PUT' || the strtoupper ( $ Method ) == 'the DELETE' ) { curl_setopt ( $ CH , CURLOPT_CUSTOMREQUEST, $ Method ); // set request mode } curl_setopt ( $ CH , CURLOPT_POSTFIELDS, $ Data ); // request data } curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); curl_setopt ( $ CH , CURLOPT_HTTPHEADER, $ header ); // simulated head header // curl_setopt ($ ch, CURLOPT_HEADER, false); // do not need header information setting $ Result = the curl_exec ( $ CH ); // execution request curl_close ( $ CH ); // close curl, release the resources return $ Result ; }