CurlHttpClient is a object oriented wrapper of PHP cURL extension. It includes a class CurlHttpClient and a set of handy apis, which are a set of static methods included in the class. Besides, a Yii framework component wrapper is provided with it.
- CurlHttpClient::getInstance()
- CurlHttpClient::get()
- CurlHttpClient::getJson()
- CurlHttpClient::post()
- CurlHttpClient::postJson()
- __construct()
- reset()
- getRequest()
- postRequest()
- setCookie()
- setCookies()
- setHeader()
- setHeaders()
- setQuery()
- setQueries()
- setCurlOption()
- getErrorCode()
- getErrorMsg()
- getRawResponseHeader()
- getResponseHeaders()
- getResponseBody()
A singleton factory to generate a single CurlHttpClient object.
void
This function will return a CurlHttpClient object when success, or false
on failure.
Simple and handy GET request
- $url --- request url
- $queries --- request parameters
- $cookies --- cookies from last request
- $headers --- headers should include
The request result will be returned in a string.
Simple and handy GET request, but the result is JSON
- $url --- request url
- $queries --- request parameters
- $cookies --- cookies from last request
- $headers --- headers should include
The request result will be treated as JSON string and before returned, the json_decode
function will be called.
Simple and handy POST request
- $url --- request url
- $queries --- request parameters
- $cookies --- cookies from last request
- $headers --- headers should include
The result string of the POST request.
Simple and handy POST request, but the result is JSON
- $url --- request url
- $queries --- request parameters
- $cookies --- cookies from last request
- $headers --- headers should include
The request result will be treated as JSON string and before returned, the json_decode
function will be called.
This static variable is set to the version of the class.
The constructor of the CurlHttpClient object.
void
void
This method will reset the cURL resource and clear the last request information.
void
void
Send the request with HTTP GET method.
- $url
The response body of the requst.
Send the request with HTTP POST method.
- $url
The response body of the requst.
Set the request cookie.
- $key string
- $value string
void
Set the request cookies by array or cookie string.
- $cookies mixed this argument could be a string like(key1=val1; key2=val2) or a associative array of PHP.
void
Set the request header with key and value.
- $key string
- $value string
void
Set headers with associative array.
- $headers array
void
Set the quest parameter.
- $key string
- $value string
void
Set multiple query parameters with query string or associative array.
- $queries mixed string/array
Set the cURL option to the cURL resource handler in the object.
- $option int this should be the cURL predefined constant.
- $value mixed
void
Get the error code the cURL returned after the request.
void
The error code of the cURL.
Get the string error message information of cURL.
void
The error message cURL generated.
Get the response header of the request. This is in raw, that means a single string, each response header in the string is separated by "\r\n"
void
The response header of the request.
Get the header string parsed result. The header string will be parse to an associative array, the header name will be the key and the header value will be the value.
void
array
void
string