1 Star 0 Fork 81

jwenlee / http-class-for-php

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

##1. 基本 get 请求:

    $http = new Http();         // 实例化对象
    $result =  $http->get('http://weibo.com/at/comment');

##2. 基本 post 请求:

$http = new Http();         // 实例化对象
$result = $http->post('http://someurl.com/post-new-article', array('title'=>$title, 'body'=>$body) );

##3. 模拟登录 ( post 和 get 同时使用, 利用 cookie 存储状态 ) :

$http = new Http();         // 实例化对象
$http->setCookiepath(substr(md5($username), 0, 10));        // 设置 cookie, 如果是多个用户请求的话
// 提交 post 数据
$loginData = $http->post('http://login.sina.com.cn/sso/login.php?client=ssologin.js(v1.3.19)', array('username'=>$username, 'loginPass'=>$password) );
$result =  $http->get('http://weibo.com/at/comment');

##4. 利用 initialize 函数设置多个 config 信息

$httpConfig['method']     = 'GET';
$httpConfig['target']     = 'http://www.somedomain.com/index.html';
$httpConfig['referrer']   = 'http://www.somedomain.com';
$httpConfig['user_agent'] = 'My Crawler';
$httpConfig['timeout']    = '30';
$httpConfig['params']     = array('var1' => 'testvalue', 'var2' => 'somevalue');

$http = new Http();
$http->initialize($httpConfig);

$result = $http->result;

##5. 复杂的设置:

$http = new Http();
$http->useCurl(false);      // 不使用 curl
$http->setMethod('POST');       // 使用 POST method

// 设置 POST 数据
$http->addParam('user_name' , 'yourusername');
$http->addParam('password'  , 'yourpassword');

// Referrer
$http->setReferrer('https://yourproject.projectpath.com/login');

// 开始执行请求
$http->execute('https://yourproject.projectpath.com/login/authenticate');
$result = $http->getResult();

##6. 获取开启了 basic auth 的请求

$http = new Http();

// Set HTTP basic authentication realms
$http->setAuth('yourusername', 'yourpassword');

// 获取某个被保护的应用的 feed
$http->get('http://www.someblog.com/protected/feed.xml');

$result = $http->result;

空文件

简介

HTTP Class for PHP , 支持 Curl 和 Socket 展开 收起
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/jwenlee/http-class-for-php.git
git@gitee.com:jwenlee/http-class-for-php.git
jwenlee
http-class-for-php
http-class-for-php
master

搜索帮助

14c37bed 8189591 565d56ea 8189591