curlite---一款轻量级的curl组件

curlite,一款轻量级的php curl组件

Github:https://github.com/zhusaidong...

php的curl功能强大,但是原生curl参数众多,无形中增大了学习和使用的成本。curlite由此诞生。

使用

composer require zhusaidong/curlite:dev-master
require_once './vendor/autoload.php';

use zhusaidong\CurLite\Request,zhusaidong\CurLite\Curl;

$request = new Request('https://www.baidu.com/s');
$request->postFields = ['wd'=>'php curl'];
$request->referer = 'https://www.baidu.com/';
$cl = new Curl($request);
$response = $cl->getResponse();
echo $response->body;

参数

Response

/**
* @var 响应header
*/
$header = [];
/**
* @var 响应body
*/
$body = '';
/**
* @var http code
*/
$httpCode = '';
/**
* @var cookie
*/
$cookie = '';
/**
* @var 错误信息,如果curl成功,$error = FALSE
*/
$error = '';

Request

/**
* get请求
*/
const METHOD_GET = 1;
/**
* post请求
*/
const METHOD_POST = 2;

/**
* @var 请求url
*/
$url = '';
/**
* @var 请求类型,默认get
*/
$method = self::METHOD_GET;
/**
* @var post数据
*/
$postFields = [];
/**
* @var 请求header
*/
$header = [];
/**
* @var referer
*/
$referer = '';
/**
* @var cookie
*/
$cookie = '';
/**
* @var user-agent
*/
$userAgent = '';
/**
* @var 请求超时时间
*/
$timeout = 3;

想要深入了解 curlite 或者反馈问题,可以关注 GitHub

相关推荐