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.
In order to install this library via composer run the following command in the console:
composer require firmaprofesional/curl
or add the package manually to your composer.json file in the require section:
"firmaprofesional/curl": "^0.3"
$curl = new CurlService();
$curlConfig = new CurlConfig();
$curlConfig->setCurlUrl('www.example.com');
$curl->configure($curlConfig);
$curl->send();
basic authentication
$curl = new CurlService();
$curlConfig = new CurlConfig();
$curlConfig->setCurlUrl('www.example.com');
$curlConfig->setUsername('user');
$curlConfig->setUserPassword('password');
$curl->configure($curlConfig);
$curl->send();
post fields
$curl = new CurlService();
$curlConfig = new CurlConfig();
$curlConfig->setCurlUrl('www.example.com');
$curlConfig->setMethodPOST();
$data_string = json_encode(array('data'));
$curlConfig->setHttpHeader(
array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string),
)
);
$curlConfig->setData($data_string);
$curl->configure($curlConfig);
$curl->send();
post fields with bearer token authentication
$curl = new CurlService();
$curlConfig = new CurlConfig();
$curlConfig->setCurlUrl('www.example.com');
$curlConfig->setMethodPOST();
$data_string = json_encode(array('data'));
$curlConfig->setHttpHeader(
array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string),
'Authorization: Bearer bearertoke'
)
);
$curlConfig->setData($data_string);
$curl->configure($curlConfig);
$curl->send();
enable verbose mode will log on tmp path
$curl = new CurlService();
$curlConfig = new CurlConfig();
$curlConfig->setCurlUrl('www.example.com');
$curlConfig->setVerbose(true);
$curl->configure($curlConfig);
$curl->send();
set timeout in seconds
$curl = new CurlService();
$curlConfig = new CurlConfig();
$curlConfig->setCurlUrl('www.example.com');
$curlConfig->setTimeout(10);
$curl->configure($curlConfig);
$curl->send();
In order to test the library:
- Create a fork
- Clone the fork to your machine
- Install the depencies
composer install
- Run the unit tests
./vendor/phpunit/bin/phpunit -c phpunit.xml --testsuite general