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