public $buf " /> 都市激情亚洲综合,日韩av字幕,超碰97成人

色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

php實現(xiàn)httpclient類示例

復(fù)制代碼 代碼如下:
httpClient::init($httpClient, $args = null);
$httpClient->get($url, $data = null, $cookie = null);
var_dump($httpClient->buffer);

復(fù)制代碼 代碼如下:
<?php

class httpClient {

 public $buffer = null;  // buffer 獲取返回的字符串
 public $referer = null;  // referer 設(shè)置 HTTP_REFERER 的網(wǎng)址
 public $response = null; // response 服務(wù)器響應(yīng)的 header 信息
 public $request = null;  // request 發(fā)送到服務(wù)器的 header 信息
 private $args = null;

 public static function init(&$instanceof, $args = array()) {
  return $instanceof = new self($args);
 }

 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);
   header('Content-Type: text/plain; charset=utf-8');
  }

 }

 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. "/r/n";
  $header .= 'Connection: close'. "/r/n";
  $header .= 'Accept: */*'. "/r/n";
  $header .= 'User-Agent: '. ( isset($this->args['userAgent']) ? $this->args['userAgent'] : $_SERVER['HTTP_USER_AGENT'] ). "/r/n";
  $header .= 'DNT: 1'. "/r/n";
  if($cookie) $header .= 'Cookie: '. $cookie. "/r/n";
  if($this->referer) $header .= 'Referer: '. $this->referer. "/r/n";

  $options = array();
  $options['http']['method'] = 'GET';
  $options['http']['header'] = $header;

  $response = get_headers($url);
  $this->request = $header;
  $this->response = implode("/r/n", $response);
  $context = stream_context_create($options);
  return $this->buffer = file_get_contents($url, false, $context);

 }

 public function post($url, $data = null, $cookie = null) {

  $parse = parse_url($url);
  $host = $parse['host'];

  $header  = 'Host: '. $host. "/r/n";
  $header .= 'Connection: close'. "/r/n";
  $header .= 'Accept: */*'. "/r/n";
  $header .= 'User-Agent: '. ( isset($this->args['userAgent']) ? $this->args['userAgent'] : $_SERVER['HTTP_USER_AGENT'] ). "/r/n";
  $header .= 'Content-Type: application/x-www-form-urlencoded'. "/r/n";
  $header .= 'DNT: 1'. "/r/n";
  if($cookie) $header .= 'Cookie: '. $cookie. "/r/n";
  if($this->referer) $header .= 'Referer: '. $this->referer. "/r/n";
  if($data) $header .= 'Content-Length: '. strlen($data). "/r/n";

  $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("/r/n", $response);
  $context = stream_context_create($options);
  return $this->buffer = file_get_contents($url, false, $context);

 }

}

httpClient::init($httpClient, array( 'debugging' => true , 'userAgent' => 'MSIE 15.0' ));
$httpClient->get('http://www.baidu.com', 'name=haowei');
echo $httpClient->request; // 獲取 請求頭部信息
echo $httpClient->response; // 獲取 響應(yīng)的頭部信息
echo $httpClient->buffer; // 獲取 網(wǎng)頁內(nèi)容

$httpClient->get('http://www.jb51.NET/ServiceLogin/', 'hash='. $time, 'uid=1;users=admin;')

echo $httpClient->buffer;

php技術(shù)php實現(xiàn)httpclient類示例,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 高密市| 微博| 和政县| 新安县| 文成县| 海伦市| 万年县| 都安| 海原县| 紫阳县| 珠海市| 安顺市| 孝昌县| 天台县| 鄂伦春自治旗| 临泉县| 砚山县| 峡江县| 阿勒泰市| 南川市| 渑池县| 连州市| 姜堰市| 仪征市| 登封市| 乐至县| 清新县| 万州区| 青海省| 昆明市| 弥渡县| 阳新县| 鄂尔多斯市| 阳新县| 双辽市| 沅陵县| 临洮县| 金秀| 河间市| 封丘县| 都昌县|