Curl request method

Source: Internet
Author: User
: This article mainly introduces the curl request method. if you are interested in the PHP Tutorial, refer to it.
/*** HTTP request sending method, currently, only CURL requests can be sent * @ param string $ url request URL * @ param array $ params request parameter * @ param string $ method request method GET/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);/* based on the request type Set specific parameters */switch (strtoupper ($ method) {case 'get': $ opts [CURLOPT_URL] = $ url .'? '. Http_build_query ($ params); break; case 'Post': // determines whether a file is transmitted. // $ 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 method! ');}/* Initialize and execute the 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 introduces the curl request method, including some content, hope to be helpful to friends who are interested in the PHP Tutorial.

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.