Download the PHP package arturdoruch/http without Composer
On this page you can find all versions of the php package arturdoruch/http. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download arturdoruch/http
More information about arturdoruch/http
Files in arturdoruch/http
Package http
Short Description HTTP client for sending HTTP requests.
License MIT
Informations about the package http
Http
HTTP client for sending HTTP requests.
Installation
Usage
Basic usage
Creating a client
Sending requests
Request can be send with dedicated methods:
or by request()
method, with prepared the ArturDoruch\Http\Request
object.
Sending multi (parallel) requests
Sending form data (parameters)
Form data can be send only with the request methods: POST
, PUT
, PATCH
and DELETE
.
For other methods form data will be used as the URL query parameters.
Request options
Request options can be set with dedicated methods on the ArturDoruch\Http\Request
object,
or as the third argument in the Client::get()
, Client::post()
, etc. methods,
or as the fourth argument in the Client::createRequest()
method.
-
cookie
stringSets the cookie to send. The cookie format must conform to the specification.
-
headers
array -
body
string|resourceSets the body plain text. If the
Content-Type
header is not specified then will be set totext/plain
. -
json
arraySets the body to JSON data. If the
Content-Type
header is not specified then will be set toapplication/json
. -
multipart
arraySets the body to a multipart form data. For sending file create the
ArturDoruch\Http\Message\FormFile
object and pass as the form field value. If theContent-Type
header is not specified then will be set tomultipart/form-data; boundary=
.
HTTP request events
While HTTP request is sending, are called two events:
request.before
- Called before sending the request.request.complete
- Called when the request is done.
To add listeners for those events call the Client::addListener()
method.
Registered listeners receives argument depend on the event to listen for. One of the:
ArturDoruch\Http\Event\BeforeEvent
- for therequest.before
eventArturDoruch\Http\Event\CompleteEvent
- for therequest.complete
event
Example of the HttpRequestListener
class.
Convert Response object to array or json
In order to convert Response object to array call Response::toArray() method.
In order to convert Response object to json call Response::toJson() method.
To determine which Response object properties should be available in converted output value use Response::expose() method. This method takes an argument "properties" with list of properties names to expose. Available names are:
- protocol
- statusCode
- reasonPhrase
- headers
- headerLines
- body
- contentType
- requestUrl
- effectiveUrl
- errorMsg
- errorNumber
- curlInfo
As default are exposed properties: statusCode, headers, body.
To expose all Response properties use exposeAll() method.
Tips
- Get actually sent request headers.