Curl Request method

Source: Internet
Author: User
/** * 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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.