PHP Curl Encapsulation get and post methods very good

Source: Internet
Author: User

Tag:info   https   param    Run    get    lin   head   http   verify   

Public Function Curl_get ($url, array $params = Array (), $timeout =5) {$ch = Curl_init (); curl_setopt ($ch, Curlopt_url, $url ); curl_setopt ($ch, Curlopt_returntransfer, 1); curl_setopt ($ch, Curlopt_connecttimeout, $timeout); $file _contents = curl_exec ($ch); Curl_close ($ch); return $file _contents; }public function Curl_post ($url, array $params = Array (), $timeout) {$ch = Curl_init ();//Initialize Curl curl_setopt ($ch, Curlopt_ URL, $url);//crawl specified Web page curl_setopt ($ch, Curlopt_header, 0);//Set HEADER curl_setopt ($ch, Curlopt_returntransfer, 1);// Requires the result to be a string and output to the screen curl_setopt ($ch, Curlopt_connecttimeout, $timeout); curl_setopt ($ch, Curlopt_post, 1);//post Submission Method curl_setopt ($ch, Curlopt_postfields, $params); $data = curl_exec ($ch);//Run Curl Curl_close ($ch); return ($data);//Output}public function Curl_get_https ($url) {$ch = Curl_init (); curl_setopt ($ch, Curlopt_url, $url); curl _setopt ($ch, Curlopt_header, false); curl_setopt ($ch, Curlopt_returntransfer, true); curl_setopt ($ch, Curlopt_ssl_verifypeer, false); Curl_setOpt ($ch, curlopt_useragent, ' mozilla/5.0 (Windows NT 6.1) applewebkit/537.11 (khtml, like Gecko) chrome/23.0.1271.1 Safar I/537.11 '); $res = curl_exec ($ch); $rescode = Curl_getinfo ($ch, Curlinfo_http_code); Curl_close ($ch); return $res; }

PHP Curl encapsulates the get and post methods very well

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.