This article mainly introduces the PHP implementation HttpClient Class example, the need for friends can refer to the following
Code as follows: Httpclient::init ($httpClient, $args = null); $httpClient->get ($url, $data = null, $cookie = null); Var_dump ($httpClient->buffer); Code as follows: <?php class HttpClient { public $buffer = null; //buffer gets the returned string public $referer = null; //referer set http_referer URL public $response = null; Header information for Response server response public $request = null; //Request header information sent to the server private $args = null; public static function init (& $instanceof, $args = Array ()) { Return $instanceof = new self ($args); &NBSP} private function __construct ($args = Array ()) { if (!is_array ($args)) $args = Array (); $this->args = $args; if (!empty ($this->args[' debugging ')) { ob_end_clean (); set_time_limit (0); & Nbsp;header (' Content-type:text/plain; Charset=utf-8 '); } &NBSP} public function get ($urL, $data = null, $cookie = null) { $parse = Parse_url ($url); $url. = Isset ($parse [' query '])? ' & '. $data: ($data? '?'. $data: "); $host = $parse [' Host ']; $header = ' Host: '. $host. "RN"; $header. = ' Connection:close '. "RN"; $header. = ' Accept: */* '. "RN"; $header. = ' user-agent: '. (Isset ($this->args[' useragent '])? $this->args[' useragent ']: $_server[' http_user_agent ']). "RN"; $header. = ' dnt:1 '. "RN"; if ($cookie) $header. = ' Cookie: '. $cookie. "RN"; if ($this->referer) $header. = ' Referer: '. $this->referer. "RN"; $options = array (); $options [' http '] [' method '] = ' get '; $options [' http '] [' header '] = $header; $response = Get_headers ($url); $this->request = $header; $this->response = implode ("rn", $response); $context = stream_context_create ($options); return $this->buffer = file_get_contents ($urL, False, $context); &NBSP} public function post ($url, $data = null, $cookie = null) { $parse = Parse_url ($u RL); $host = $parse [' Host ']; $header = ' Host: '. $host. "RN"; $header. = ' Connection:close '. "RN"; $header. = ' Accept: */* '. "RN"; $header. = ' user-agent: '. (Isset ($this->args[' useragent '])? $this->args[' useragent ']: $_server[' http_user_agent ']). "RN"; $header. = ' content-type:application/x-www-form-urlencoded '. "RN"; $header. = ' dnt:1 '. "RN"; if ($cookie) $header. = ' Cookie: '. $cookie. "RN"; if ($this->referer) $header. = ' Referer: '. $this->referer. "RN"; if ($data) $header. = ' Content-length: '. Strlen ($data). "RN"; $options = array (); $options [' http '] [' method '] = ' POST '; $options [' http '] [' header '] = $header; if ($data) $options [' http '] [' content '] = $data; $response = Get_headers ($url); $tHis->request = $header; $this->response = implode ("rn", $response); $context = stream_context_create ($options); return $this->buffer = file_get_contents ($url, False, $context); &NBSP} } Httpclient::init ($httpClient, Array (' Debugging ' => true, ' useragent ' => ' msie ' 15.0 ') )); $httpClient->get (' http://www.baidu.com ', ' Name=haowei '); Echo $httpClient->request; Get request header information echo $httpClient->response; Gets the header information for the response echo $httpClient->buffer; Get Web content $httpClient->get (' http://www.jb51.net/ServiceLogin/', ' hash= '. $time, ' uid=1;users=admin; ') Echo $httpClient->buffer;