项目作者: ammarfaizi2

项目描述 :
PHP Curl
高级语言: PHP
项目地址: git://github.com/ammarfaizi2/phpcurl.git
创建时间: 2017-05-14T23:24:07Z
项目社区:https://github.com/ammarfaizi2/phpcurl

开源协议:MIT License

下载


PHP Curl Class

This library provides an object-oriented wrapper of the PHP cURL extension.

If you have questions or problems with installation or usage create an Issue.

Installation

In order to install this library via composer run the following command in the console:

  1. composer require curl/curl

or add the package manually to your composer.json file in the require section:

  1. "curl/curl": "^1.5"

Usage examples

  1. $curl = new Curl\Curl();
  2. $curl->get('http://www.example.com/');
  1. $curl = new Curl\Curl();
  2. $curl->get('http://www.example.com/search', array(
  3. 'q' => 'keyword',
  4. ));
  1. $curl = new Curl\Curl();
  2. $curl->post('http://www.example.com/login/', array(
  3. 'username' => 'myusername',
  4. 'password' => 'mypassword',
  5. ));
  1. $curl = new Curl\Curl();
  2. $curl->setBasicAuthentication('username', 'password');
  3. $curl->setUserAgent('');
  4. $curl->setReferrer('');
  5. $curl->setHeader('X-Requested-With', 'XMLHttpRequest');
  6. $curl->setCookie('key', 'value');
  7. $curl->get('http://www.example.com/');
  8. if ($curl->error) {
  9. echo $curl->error_code;
  10. }
  11. else {
  12. echo $curl->response;
  13. }
  14. var_dump($curl->request_headers);
  15. var_dump($curl->response_headers);
  1. $curl = new Curl\Curl();
  2. $curl->setOpt(CURLOPT_RETURNTRANSFER, TRUE);
  3. $curl->setOpt(CURLOPT_SSL_VERIFYPEER, FALSE);
  4. $curl->get('https://encrypted.example.com/');
  1. $curl = new Curl\Curl();
  2. $curl->put('http://api.example.com/user/', array(
  3. 'first_name' => 'Zach',
  4. 'last_name' => 'Borboa',
  5. ));
  1. $curl = new Curl\Curl();
  2. $curl->patch('http://api.example.com/profile/', array(
  3. 'image' => '@path/to/file.jpg',
  4. ));
  1. $curl = new Curl\Curl();
  2. $curl->delete('http://api.example.com/user/', array(
  3. 'id' => '1234',
  4. ));
  1. $curl->close();
  1. // Example access to curl object.
  2. curl_set_opt($curl->curl, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1');
  3. curl_close($curl->curl);

Testing

In order to test the library:

  1. Create a fork
  2. Clone the fork to your machine
  3. Install the depencies composer install
  4. Run the unit tests ./vendor/bin/phpunit tests