vis / curl_client_l5
PHP cUrl 扩展包装器
1.0.3
2017-05-08 18:26 UTC
This package is not auto-updated.
Last update: 2024-09-13 23:21:15 UTC
README
PHP cUrl 扩展包装器。
执行
composer require "vis/curl_client_l5":"1.*"
用法
$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
执行 cUrl 请求
$curl->doCurlRequest() //returns self
之后,您可以使用以下方法获取请求响应
$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
您还可以使用辅助方法 isSuccessful 来检查响应 HTTP 状态码是否在 200 到 300 范围内
$curl->isSuccessful();
如果您希望提前关闭 cUrl 资源(此方法在对象销毁时也会执行)
$curl->doCloseCurl();