Package Data | |
---|---|
Maintainer Username: | zjango |
Maintainer Contact: | zjango@icloud.com (zjango) |
Package Create Date: | 2016-09-28 |
Package Last Update: | 2018-03-02 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-17 03:05:37 |
Package Statistics | |
---|---|
Total Downloads: | 9,942 |
Monthly Downloads: | 1 |
Daily Downloads: | 1 |
Total Stars: | 0 |
Total Watchers: | 1 |
Total Forks: | 1 |
Total Open Issues: | 1 |
Laravel-Curl is an object-oriented wrapper of the PHP cURL extension.
To install the package, simply add the following to your Laravel installation's composer.json
file
"require": {
"zjango/laracurl": "dev-master"
},
Run the usual composer update
to pull the files. Then, add the following Service Provider to your providers
array in your config/app.php
config.
'providers' => array(
...
'Zjango\Curl\CurlServiceProvider',
);
And finally add a new line to the aliases array:
'Curl' => 'Zjango\Curl\Facades\Curl',
Run the usual composer update
to pull the files. Then, add the following Service Provider to your providers
array in your config/app.php
config.
'providers' => array(
...
Zjango\Curl\CurlServiceProvider::class,
);
And finally add a new line to the aliases array:
'Curl' => Zjango\Curl\Facades\Curl::class,
Simple GET Request
Curl::get('http://www.example.com/');
Easily Build URL With Query String Attached
Curl::buildUrl('http://www.example.com/search', array(
'q' => 'keyword',
));
Easily GET Request With Query String Attached
Curl::get('http://www.example.com/search', array(
'q' => 'keyword',
));
post() accepts array of POST data
Curl::post('http://www.example.com/login/', array(
'username' => 'myusername',
'password' => 'mypassword',
));
Prefix 'json' to method to post as JSON //todo
Prefix 'raw' to method to post as JSON //todo
$curl = new Curl;
$curl->setBasicAuthentication('username', 'password');
$curl->setUserAgent('');
$curl->setReferrer('');
$curl->setHeader('X-Requested-With', 'XMLHttpRequest');
$curl->setCookie('key', 'value');
$curl->get('http://www.example.com/');
if ($curl->error) {
echo $curl->error_code;
}
else {
echo $curl->body;
}
var_dump($curl->request_headers);
var_dump($curl->response_headers);
$curl = new Curl;
$curl->setopt(CURLOPT_RETURNTRANSFER, TRUE);
$curl->setopt(CURLOPT_SSL_VERIFYPEER, FALSE);
$curl->get('https://encrypted.example.com/');
Curl::put('http://api.example.com/user/', array(
'first_name' => 'Zach',
'last_name' => 'Borboa',
));
Curl::patch('http://api.example.com/profile/', array(
'image' => '@path/to/file.jpg',
));
Curl::delete('http://api.example.com/user/', array(
'id' => '1234',
));
$curl->close();
###The Response Object###
The $response
variable in above examples represents an object as well.
// Return cURL and http status (bool)
$response->error
// Return cURL error or http error code
$response->error_code
// cURL error or http error message
$response->error_message
// curl error (bool)
$response->curl_error
// curl error code
$response->curl_error_code
// curl error message
$response->curl_error_message
// http error (bool)
$response->http_error
// Response http status code
$response->http_status_code
// Response http error message
$response->http_error_message
// Request _cookies
$response->_cookies
// set _headers
$response->_headers
// Request request_headers
$response->request_headers
// Return Headers
$response->response_headers
// cURL Info
$response->info
// Response Body
$response->body