/** * Send HTTP request method, currently only support curl Send request * @param string $url request URL * @param array $params request parameter * @param string $method request method G Et/post * @return Array $data response Data */function http ($url, $params, $method = ' GET ', $header = Array (), $multi = False) {$ opts = Array (curlopt_timeout = 30,curlopt_returntransfer = 1,curlopt_ssl_verifypeer = False,curlopt_ssl _verifyhost = False,curlopt_httpheader = $header);/* Set specific Parameters */switch (Strtoupper ($method)) {case ' GET ' by request type: $o Pts[curlopt_url] = $url. '?' . Http_build_query ($params); Break;case ' POST '://Determine whether to transfer files//$params = $multi? $params: Http_build_query ($params); $opts [Curlopt_url] = $url; $opts [Curlopt_post] = 1; $opts [Curlopt_postfields] = $ Params;break;default:throw New Exception (' Unsupported request mode! ');} /* Initialize and perform curl request */$ch = Curl_init () curl_setopt_array ($ch, $opts); $data = Curl_exec ($ch); $error = Curl_error ($ch); curl_ Close ($ch), if ($error) throw new Exception (' request error: '. $error); return $data;}
The above describes the curl request method, including the aspects of the content, I hope the PHP tutorial interested in a friend helpful.