PHP's Curl function related questions

Source: Internet
Author: User

A. Question and answer question

1.curl_setopt timeout settings, URL settings, post data receive settings, decompression settings, header information set the parameter name is what?

What is the function of 2.curl batch setup parameters?

Two. Programming questions

1. Encapsulate a curl class, provide the Get,post method, by passing url,data data to get the content of a URL, method return information format is array (' response ' = ' "Web content ', ' status ' = ' HTTP request status code ') , ' error ' = ' wrong message ')

Request can change header information, and there is a timeout mechanism, zip decompression function

A. Question and answer question

1.curlopt_timeout,curlopt__url,curlopt_postfileds,curlopt_encoding,curlopt_httpheader

2.curl_setopt_array ($ch, $options);

Two. Programming questions

1.

<?PHPclasscurl{Private $ch= ' '; Private $timeout= 5;  Public  $options=Array();  Public  $headers=Array();  Public  $url= ' '; function__construct () {$thisCH =Curl_init (); $this-headers[] = "Accept: */*"; $this-headers[] = "ACCEPT-ENCODING:GZIP,DEFLATE,SDCH"; $this-headers[] = "Connection:keep-alive"; }     Public functionGet$url,$timeout=NULL)    {        $thisURL =$url; $this-Options[curlopt_timeout] =$timeout?$timeout:$this-timeout; $this-setopt (); return $this-result (); }     Public functionPost$url,$data,$timeout=NULL)    {        $thisURL =$url; $this-Options[curlopt_timeout] =$timeout?$timeout:$this-timeout; $this-Options[curlopt_post] =true; $this-Options[curlopt_postfields] =$data; $this-setopt (); return $this-result (); }        Private functionsetopt () {curl_setopt ($thisCH, Curlopt_url,$this-URL); curl_setopt ($thisCH, Curlopt_returntransfer,true); curl_setopt ($this-ch, curlopt_encoding, ' gzip '); curl_setopt ($thisCH, Curlopt_httpheader,$this-headers); Curl_setopt_array ($this-CH,$this-options); }    Private functionExecs () {returnCurl_exec ($this-ch);} Private functionStatus () {returnCurl_getinfo ($this-CH,curlinfo_http_code);} Private functionError () {return(Curl_errno ($this(CH))? Curl_error ($thisCH): ';} Private functionresult () {$result[' response '] =$this-execs (); $result[' status '] =$this-status (); $result[' ERROR '] =$this-error (); return $result; }}

PHP's Curl function related questions

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.