Class Client

Summary

Fully Qualified Name: Zend\Http\Client
Implements: DispatchableInterface

Description

Http client

Methods

Name Description Defined By
__construct() Constructor Client
addCookie() Add a cookie Client
clearAuth() Clear http authentication Client
clearCookies() Clear all the cookies Client
dispatch() Dispatch Client
encodeAuthHeader() Create a HTTP authentication "Authorization:" header according to the specified user, password and authentication method. Client
encodeFormData() Encode data to a multipart/form-data part suitable for a POST request. Client
getAdapter() Load the connection adapter Client
getArgSeparator() Get the query string argument separator Client
getCookies() Return the current cookies Client
getEncType() Get the encoding type Client
getHeader() Get the header value of the request Client
getLastRawRequest() Get the last request (as a string) Client
getLastRawResponse() Get the last response (as a string) Client
getMethod() Get the HTTP method Client
getRedirectionsCount() Get the redirections count Client
getRequest() Get Request Client
getResponse() Get Response Client
getStream() Get status of streaming for received data Client
getUri() Get uri (from the request) Client
hasHeader() Check if exists the header type specified Client
removeFileUpload() Remove a file to upload Client
reset() Fully reset the HTTP client (auth, cookies, request, response, etc.) Client
resetParameters() Reset all the HTTP parameters (request, response, etc) Client
send() Send HTTP request Client
setAdapter() Load the connection adapter Client
setArgSeparator() Set the query string argument separator Client
setAuth() Create a HTTP authentication "Authorization:" header according to the specified user, password and authentication method. Client
setCookies() Set an array of cookies Client
setEncType() Set the encoding type and the boundary (if any) Client
setFileUpload() Set a file to upload (using a POST request) Client
setHeaders() Set the headers (for the request) Client
setMethod() Set the HTTP method (to the request) Client
setOptions() Set configuration parameters for this HTTP client Client
setParameterGet() Set the GET parameters Client
setParameterPost() Set the POST parameters Client
setRawBody() Set raw body (for advanced use cases) Client
setRequest() Set request Client
setResponse() Set response Client
setStream() Set streaming for received data Client
setUri() Set Uri (to the request) Client

Method Details

__construct()

Constructor

Parameter Name Type Description
$uri string
$options array|\Traversable

Returns:

addCookie()

Add a cookie

Parameter Name Type Description
$cookie array|\ArrayIterator|\Header\SetCookie|string
$value string
$expire string
$path string
$domain string
$secure bool
$httponly bool
$maxAge string
$version string

Returns: \Client

clearAuth()

Clear http authentication

Returns:

clearCookies()

Clear all the cookies

Returns:

dispatch()

Dispatch

Parameter Name Type Description
$request \Stdlib\RequestInterface
$response \Stdlib\ResponseInterface

Returns: \Stdlib\ResponseInterface

encodeAuthHeader()

Create a HTTP authentication "Authorization:" header according to the specified user, password and authentication method.

Parameter Name Type Description
$user string
$password string
$type string

Returns: string

encodeFormData()

Encode data to a multipart/form-data part suitable for a POST request.

Parameter Name Type Description
$boundary string
$name string
$value mixed
$filename string
$headers array Associative

Returns: string

getAdapter()

Load the connection adapter

Returns: \Client\Adapter\AdapterInterface $adapter

getArgSeparator()

Get the query string argument separator

Returns: string

getCookies()

Return the current cookies

Returns: array

getEncType()

Get the encoding type

Returns: string

getHeader()

Get the header value of the request

Parameter Name Type Description
$name string

Returns: string|bool

getLastRawRequest()

Get the last request (as a string)

Returns: string

getLastRawResponse()

Get the last response (as a string)

Returns: string

getMethod()

Get the HTTP method

Returns: string

getRedirectionsCount()

Get the redirections count

Returns: int

getRequest()

Get Request

Returns: \Request

getResponse()

Get Response

Returns: \Response

getStream()

Get status of streaming for received data

Returns: bool|string

getUri()

Get uri (from the request)

Returns: \Http

hasHeader()

Check if exists the header type specified

Parameter Name Type Description
$name string

Returns: bool

removeFileUpload()

Remove a file to upload

Parameter Name Type Description
$filename string

Returns: bool

reset()

Fully reset the HTTP client (auth, cookies, request, response, etc.)

Returns: \Client

resetParameters()

Reset all the HTTP parameters (request, response, etc)

Parameter Name Type Description
$clearCookies bool Also
$clearAuth bool Also

Returns: \Client

send()

Send HTTP request

Parameter Name Type Description
$request \Request

Returns: \Response

setAdapter()

Load the connection adapter

While this method is not called more than one for a client, it is separated from ->request() to preserve logic and readability

Parameter Name Type Description
$adapter \Client\Adapter\AdapterInterface|string

Returns: \Client

setArgSeparator()

Set the query string argument separator

Parameter Name Type Description
$argSeparator string

Returns: \Client

setAuth()

Create a HTTP authentication "Authorization:" header according to the specified user, password and authentication method.

Parameter Name Type Description
$user string
$password string
$type string

Returns: \Client

setCookies()

Set an array of cookies

Parameter Name Type Description
$cookies array

Returns: \Client

setEncType()

Set the encoding type and the boundary (if any)

Parameter Name Type Description
$encType string
$boundary string

Returns: \Client

setFileUpload()

Set a file to upload (using a POST request)

Can be used in two ways:

  1. $data is null (default): $filename is treated as the name if a local file which will be read and sent. Will try to guess the content type using mime_content_type().
  2. $data is set - $filename is sent as the file name, but $data is sent as the file contents and no file is read from the file system. In this case, you need to manually set the Content-Type ($ctype) or it will default to application/octet-stream.
Parameter Name Type Description
$filename string Name
$formname string Name
$data string Data
$ctype string Content

Returns: \Client

setHeaders()

Set the headers (for the request)

Parameter Name Type Description
$headers \Headers|array

Returns: \Client

setMethod()

Set the HTTP method (to the request)

Parameter Name Type Description
$method string

Returns: \Client

setOptions()

Set configuration parameters for this HTTP client

Parameter Name Type Description
$options array|\Traversable

Returns: \Client

setParameterGet()

Set the GET parameters

Parameter Name Type Description
$query array

Returns: \Client

setParameterPost()

Set the POST parameters

Parameter Name Type Description
$post array

Returns: \Client

setRawBody()

Set raw body (for advanced use cases)

Parameter Name Type Description
$body string

Returns: \Client

setRequest()

Set request

Parameter Name Type Description
$request \Request

Returns: \Client

setResponse()

Set response

Parameter Name Type Description
$response \Response

Returns: \Client

setStream()

Set streaming for received data

Parameter Name Type Description
$streamfile string|bool Stream

Returns: \Zend\Http\Client

setUri()

Set Uri (to the request)

Parameter Name Type Description
$uri string|\Http

Returns: \Client

Top