2017 © Pedro Peláez
 

library http

php http request

image

opdss/http

php http request

  • Tuesday, January 9, 2018
  • by opdss
  • Repository
  • 1 Watchers
  • 0 Stars
  • 43 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 13 % Grown

The README.md

Opdss/Http

简介

一个基于PHP cURL的开源HTTP类库,支持链式操作,省去繁杂的cURL使用方法。, (*1)

用法

链式调用

<?php
$http = Request::factory();
$response = $http->retry(3) // 失败重试3次
                 ->ua('Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)')
                 ->referer('http://www.baidu.com/')
                 ->accept('text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8')
                 ->acceptLanguage('zh-CN,zh;q=0.8')
                 ->get('http://www.baidu.com/');
var_dump($response);

GET

<?php
$http = Request::factory();
$response = $http->get('http://www.baidu.com/');
var_dump($response);

POST(x-www-form-urlencoded)

<?php
$requestBody = array(
    'lang' => 'php',
    'ver'  => 'any'
);
$http = Request::factory();
$response = $http->post('http://www.baidu.com/', $requestBody);
var_dump($response);

POST(raw)

<?php
$requestBody = <<<EOF
{
    'lang': 'php',
    'ver':  'any'
}
EOF;
$http = Request::factory();
$http->contentType('application/json');
$response = $http->post('http://www.baidu.com/', $requestBody);
var_dump($response);

POST(multi_part)

<?php
$requestBody = new RequestMultipartBody();
$requestBody->add('name', 'php');
$requestBody->addFile('file', '/path/to/aaa.txt', 'aaa.txt');
$http = Request::factory();
$response = $http->post('http://www.baidu.com/', $requestBody);
var_dump($response);

FTP下载

<?php
$url = 'ftp://用户名:密码@IP地址/文件路径';
$url = 'ftp://IP地址/文件路径';
$http = Request::factory();
// $http->userPwd('用户名','密码'); // 除了在URL里,也可以用这种方式设置密码
$http->saveFile('./')->get($url); // 使用ftp服务器中的文件名保存到当前目录
$http->saveFile('./abc.txt')->get($url); // 指定文件名保存

具体详见Demo, (*2)

The Versions

09/01 2018

dev-master

9999999-dev http://php.istimer.com/

php http request

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

http request

09/01 2018

v1.2.6

1.2.6.0 http://php.istimer.com/

php http request

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

http request

08/01 2018

v1.2.0

1.2.0.0 http://www.istimer.com/

php http request

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

http request

21/06 2017

1.0.0

1.0.0.0 http://www.istimer.com/

php http request

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

http request

31/05 2017

v0.9

0.9.0.0 http://www.istimer.com/

php http request

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

http request