最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2014年04月08日 09:37:14   作者:  
這篇文章主要介紹了php實(shí)現(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; // 獲取 請(qǐng)求頭部信息
echo $httpClient->response; // 獲取 響應(yīng)的頭部信息
echo $httpClient->buffer; // 獲取 網(wǎng)頁(yè)內(nèi)容

$httpClient->get('http://m.fzitv.net/ServiceLogin/', 'hash='. $time, 'uid=1;users=admin;')

echo $httpClient->buffer;

相關(guān)文章

  • PHP爬蟲框架盤點(diǎn)

    PHP爬蟲框架盤點(diǎn)

    大數(shù)據(jù)分析必定少不了數(shù)據(jù)抓取,只有擁有海量的數(shù)據(jù)才能對(duì)數(shù)據(jù)進(jìn)行對(duì)比分析。因此,網(wǎng)頁(yè)爬蟲是作為程序員必須要懂得技能,下文我將通過(guò)文字形式記錄下php的爬蟲框架的一些內(nèi)容。需要的小伙伴可以借鑒一下
    2023-04-04
  • php 搜索框提示(自動(dòng)完成)實(shí)例代碼

    php 搜索框提示(自動(dòng)完成)實(shí)例代碼

    輸入要搜索的文字時(shí)在搜索框下方提示相關(guān)的搜索信息實(shí)現(xiàn)方法,就是自動(dòng)完成效果
    2012-02-02
  • Zend Framework教程之路由功能Zend_Controller_Router詳解

    Zend Framework教程之路由功能Zend_Controller_Router詳解

    這篇文章主要介紹了Zend Framework教程之路由功能Zend_Controller_Router,詳細(xì)分析了路由功能Zend_Controller_Router的原理,使用技巧與相關(guān)注意事項(xiàng),需要的朋友可以參考下
    2016-03-03
  • 新版php?study根目錄下文件夾無(wú)法顯示的圖文解決方法

    新版php?study根目錄下文件夾無(wú)法顯示的圖文解決方法

    這篇文章主要介紹了新版php?study根目錄下文件夾無(wú)法顯示解決方法,本文通過(guò)圖文并茂的形式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-12-12
  • php微信授權(quán)登錄實(shí)例講解

    php微信授權(quán)登錄實(shí)例講解

    這篇文章主要介紹了php微信授權(quán)登錄實(shí)例講解,微信授權(quán)登錄是比較常用的功能,有需要的同學(xué)可以研究下
    2021-03-03
  • laravel 實(shí)現(xiàn)用戶登錄注銷并限制功能

    laravel 實(shí)現(xiàn)用戶登錄注銷并限制功能

    今天小編就為大家分享一篇laravel 實(shí)現(xiàn)用戶登錄注銷并限制功能,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2019-10-10
  • Yii框架擴(kuò)展CGridView增加導(dǎo)出CSV功能的方法

    Yii框架擴(kuò)展CGridView增加導(dǎo)出CSV功能的方法

    這篇文章主要介紹了Yii框架擴(kuò)展CGridView增加導(dǎo)出CSV功能的方法,結(jié)合實(shí)例形式較為詳細(xì)的分析了Yii框架擴(kuò)展組件實(shí)現(xiàn)導(dǎo)出CSV格式數(shù)據(jù)的具體步驟與相關(guān)操作技巧,需要的朋友可以參考下
    2017-05-05
  • ThinkPHP中圖片按比例切割的代碼實(shí)例

    ThinkPHP中圖片按比例切割的代碼實(shí)例

    今天小編就為大家分享一篇關(guān)于ThinkPHP中圖片按比例切割的代碼實(shí)例,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧
    2019-03-03
  • Thinkphp自定義代碼生成工具及用法說(shuō)明(附下載地址)

    Thinkphp自定義代碼生成工具及用法說(shuō)明(附下載地址)

    這篇文章主要介紹了Thinkphp自定義代碼生成工具及用法說(shuō)明,簡(jiǎn)單分析了自定義代碼生成工具的作用及用法,并附帶了下載地址,需要的朋友可以參考下
    2016-05-05
  • tp5框架的增刪改查操作示例

    tp5框架的增刪改查操作示例

    這篇文章主要介紹了tp5框架的增刪改查操作,結(jié)合實(shí)例形式分析了thinkPHP5框架數(shù)據(jù)庫(kù)連接及增刪改查相關(guān)操作的控制器與視圖使用技巧,需要的朋友可以參考下
    2019-10-10

最新評(píng)論

吕梁市| 赤壁市| 柘城县| 弥渡县| 太康县| 隆安县| 昌都县| 集安市| 东辽县| 桃源县| 安仁县| 福贡县| 台中市| 邵武市| 邵阳市| 盐边县| 苍山县| 阿拉尔市| 盘锦市| 沧州市| 舒兰市| 巴彦淖尔市| 兴安县| 崇明县| 嘉义县| 浮山县| 邓州市| 太谷县| 威远县| 连云港市| 东辽县| 康马县| 柘荣县| 中江县| 台中市| 明溪县| 邮箱| 将乐县| 福泉市| 通河县| 枞阳县|