PHP cUrl extension wrapper
PHP cUrl extension wrapper., (*1)
Execute, (*2)
composer require "vis/curl_client_l5":"1.*"
Usage, (*3)
$curl = New Vis/CurlClient/CurlClient(); //example of all possible methods $curl->setRequestCredentials($login, $password, $authType) //$authType is optional ->setRequestHeader($option, $value) //$option accepts array ["option" => "value", "option1" => "value1"] ->setRequestCookie($option, $value) //$option accepts array ["option" => "value", "option1" => "value1"] ->setRequestReferrer($referrer) ->setRequestUserAgent($agent) ->setRequestMethod($method) // 'POST', 'GET', 'PUT', 'PATCH', 'DELETE' ->setRequestUrl($url,$urlParams) //$urlParam is optional if you need to add params to query string ->setRequestPayload($payload, $encoding) // $encoding is optional. Accepts either 'json' or 'query' and encodes payload to given format, otherwise doesn't encode. ->setCurlOpt($option, $value) //if you need to set any other additional curl options
To execute curl request, (*4)
$curl->doCurlRequest() //returns self
After that you can get request response with following methods, (*5)
$curl->getCurlResponse(); //returns array ['http_code', 'response_header', 'response_body'] $curl->getCurlResponseHttpCode(); //returns http_code $curl->getCurlResponseHeader(); //returns response_header $curl->getCurlResponseBody(); //returns response_body
Also you can use helper method isSuccessful to check if response http code was in range from 200 to 300, (*6)
$curl->isSuccessful();
If you wish to close curl resource earlier (this method is also executed upon destruction of object), (*7)
$curl->doCloseCurl();