PHP Curl function, support post get

Source: Internet
Author: User
Tags array curl return
/** * @author default7 
 
  

 * @param $url * @param string $method * @param array $postData * * @return mixednullstring * * * functio

    N Gethttpcontent ($url, $method = ' get ', $postData = Array ()) {$data = ';
            if (!empty ($url)) {try {$ch = Curl_init ();
            curl_setopt ($ch, Curlopt_url, $url);
            curl_setopt ($ch, Curlopt_header, false);
            curl_setopt ($ch, Curlopt_returntransfer, 1); curl_setopt ($ch, Curlopt_timeout, 30);
            30 sec Timeout curl_setopt ($ch, curlopt_followlocation, 1);
            curl_setopt ($ch, Curlopt_cookiefile, $cookie _jar);
                if (Strtoupper ($method) = = ' POST ') {$curlPost = Http_build_query ($postData);
                curl_setopt ($ch, Curlopt_post, 1);
            curl_setopt ($ch, Curlopt_postfields, $curlPost);
            } $data = Curl_exec ($ch);
        Curl_close ($ch);
        The catch (Exception $e) {$data = null; } return $Data
 }
 



Related Article

Alibaba Cloud 10 Year Anniversary

With You, We are Shaping a Digital World, 2009-2019

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.