项目作者: zhusaidong

项目描述 :
a light-weight php curl
高级语言: PHP
项目地址: git://github.com/zhusaidong/curlite.git
创建时间: 2017-12-18T03:26:51Z
项目社区:https://github.com/zhusaidong/curlite

开源协议:BSD 2-Clause "Simplified" License

下载


CurLite

About

a Light-weight php curl

Usage

  1. composer require zhusaidong/curlite

Examples

  1. require_once './vendor/autoload.php';
  2. use zhusaidong\CurLite\Request,zhusaidong\CurLite\Curl;
  3. $request = new Request('https://github.com/search');
  4. $request->postFields = ['q'=>'php curl','type'=>''];
  5. $request->referer = 'https://github.com/';
  6. $cl = new Curl($request);
  7. $response = $cl->getResponse();
  8. //if curl successed, the `$response->error` will equal `FALSE`.
  9. if($response->error === FALSE)
  10. {
  11. echo $response->body;
  12. }
  13. else
  14. {
  15. echo 'error:'.$response->error;
  16. }

Available Properties

Response Properties

  1. /**
  2. * @var array $header response header
  3. */
  4. $header = [];
  5. /**
  6. * @var string $body response body
  7. */
  8. $body = '';
  9. /**
  10. * @var int $httpCode http code
  11. */
  12. $httpCode = '';
  13. /**
  14. * @var string $cookie cookie
  15. */
  16. $cookie = '';
  17. /**
  18. * @var array $serverInfo server info
  19. */
  20. $serverInfo = [];
  21. /**
  22. * @var string|booean $error error msg, if curl successed, the $error is FALSE
  23. */
  24. $error = '';

Request Properties

  1. /**
  2. * @const method get
  3. */
  4. const METHOD_GET = 1;
  5. /**
  6. * @const method post
  7. */
  8. const METHOD_POST = 2;
  9. /**
  10. * @var string $url request url
  11. */
  12. $url = '';
  13. /**
  14. * @var int $method request method, default is GET
  15. */
  16. $method = self::METHOD_GET;
  17. /**
  18. * @var array $postFields request post data
  19. */
  20. $postFields = [];
  21. /**
  22. * @var array $header request header
  23. */
  24. $header = [];
  25. /**
  26. * @var string $referer request referer
  27. */
  28. $referer = '';
  29. /**
  30. * @var string $cookie cookie
  31. */
  32. $cookie = '';
  33. /**
  34. * @var string $userAgent user-agent
  35. */
  36. $userAgent = '';
  37. /**
  38. * @var boolean $isRandomIP is curl use random IP, default is FALSE
  39. */
  40. $isRandomIP = FALSE;
  41. /**
  42. * @var string $caPath cafile path
  43. */
  44. $caPath = '';
  45. /**
  46. * @var int $timeout request timeout
  47. */
  48. $timeout = 3;
  49. /**
  50. * @var int $followLocation follow the location,
  51. * set it zero can intercept the redirect
  52. */
  53. $followLocation = 1;