PHP Curl Pass Data

Source: Internet
Author: User

<?phpheader ("content-type:text/html;    Charset=utf-8 "); /*** Curl Passes data */class Curl {private $curl _resource;private $url = ';p rivate $input = Array ();p rivate $curl _error = ';p ri vate $curl _info = ";p ublic $response;p ublic function __construct ($url) {$this->url = $url;} Public Function Get_info () {return array (' url ' = = $this->url, ' input ' = = $this->input, ' Curl_error ' =>$ This->curl_error, ' curl_info ' = $this->curl_info);} Private Function Connect () {$this->curl_resource = Curl_init (); curl_setopt ($this->curl_resource, Curlopt_ HEADER, 0); Filter HTTP Header curl_setopt ($this->curl_resource,curlopt_returntransfer, 1);//Display Output curl_setopt ($this->curl_    Resource, Curlopt_timeout, 30);        Set the timeout limit to prevent the dead loop}public function post ($input) {$this->connect (); $input = (array) $input; $this->input = $input; $input = Http_build_query ($input);        Generates a UrlEncode request string based on an array curl_setopt ($this->curl_resource, Curlopt_url, $this->url); curl_setopt ($this-&Gt;curl_resource,curlopt_post,true); Post transmission Data curl_setopt ($this->curl_resource,curlopt_postfields, $input);        Post transmits data $this->curl_error = Curl_error ($this->curl_resource);        $this->curl_info = curl_getinfo ($this->curl_resource);        $this->response = curl_exec ($this->curl_resource); Curl_close ($this->curl_resource); return $this->response;}        Public function Get ($input) {$this->connect (); $input = (array) $input; $this->input = $input; $input = $this->url. '? '.        Http_build_query ($input);        curl_setopt ($this->curl_resource, Curlopt_url, $input);        $this->response = curl_exec ($this->curl_resource); Curl_close ($this->curl_resource); return $this->response;}} $curl = new Curl (' http://www.test.com/index.php ');p rint_r ($curl->post (' Post pass Data ')) Var_dump ($curl->get_info ());p Rint_r ($curl->get (' Get Pass Data ')), Var_dump ($curl->get_info ());

PHP Curl Pass Data

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.