dev-master
9999999-devA wrapper for cURL that makes it easy to use/manage requests and responses.
CC BY-NC-ND 4.0
The Requires
- php >=5.5.0
by Weidi Zhang
A wrapper for cURL that makes it easy to use/manage requests and responses.
Created by Weidi Zhang, (*1)
Easily make HTTP requests and get response information with cURL., (*2)
composer require weidizhang/php-curl-wrapper:dev-master
First, require the autoloader and use the Curl class., (*3)
require "vendor/autoload.php"; use weidizhang\PHPCurlWrapper\Curl;
Create a new Curl object, (*4)
$curl = new Curl();
use weidizhang\PHPCurlWrapper\Behavior; $curl->setBehavior( ... );
Options: KEEP_HEADERS, CLEAR_HEADERS., (*5)
See src/Behavior.php to see what these do., (*6)
Default: CLEAR_HEADERS, (*7)
$curl->setReferer( ... ); $curl->setUserAgent( ... ); $curl->setHeader( name, value ); $curl->setHeaders( array( "Header1: value1", "Header2: value2" ) ); $curl->unsetHeader( name ); $curl->setCookieFile( filename or path ); $curl->enableSSLVerify(); $curl->disableSSLVerify();
You can pass in the option either as a constant or string., (*8)
All these do the same thing:, (*9)
$curl->setOption(CURLOPT_FRESH_CONNECT, true); $curl->setOption("CURLOPT_FRESH_CONNECT", true); $curl->setOption("FRESH_CONNECT", true);
$response = $curl->request( type, url, query [optional], options [optional] );
type = GET, POST, HEAD, PUT, etc. Custom request types are supported., (*10)
url = URL., (*11)
query = Query to send, it can be an array or string., (*12)
options = An array of curl options to set. It calls $curl->setOption( ... );
for them., (*13)
If you need access to the cURL handle for whatever reason:, (*14)
$curl->getHandle();
Getting body data: (Both work), (*15)
$body = $response; $body = $response->getBody();
Getting cURL request information:, (*16)
$info = $response->getInfo();
Getting all headers:, (*17)
$headers = $response->getHeaders();
Getting a specific header:, (*18)
$header = $response->getHeader( name );
Checking for errors (Usually not necessary):, (*19)
if ($response->hasError()) { $error = $response->getError(); }
Please read LICENSE.md to learn about what you can and cannot do with this source code., (*20)
A wrapper for cURL that makes it easy to use/manage requests and responses.
CC BY-NC-ND 4.0