Http client

 Methods

Constructor

__construct(string $uri, array | \Traversable $options) 

Parameters

$uri

string

$options

array\Traversable

Add a cookie

addCookie(array | \ArrayIterator | \Zend\Http\Header\SetCookie | string $cookie, string $value, string $expire, string $path, string $domain, bool $secure, bool $httponly, string $maxAge, string $version) : \Zend\Http\Client

Parameters

$value

string

$expire

string

$path

string

$domain

string

$secure

bool

$httponly

bool

$maxAge

string

$version

string

Exceptions

\Zend\Http\Exception\InvalidArgumentException

Returns

Clear http authentication

clearAuth() 

Clear all the cookies

clearCookies() 

Dispatch

dispatch(\Zend\Stdlib\RequestInterface $request, \Zend\Stdlib\ResponseInterface $response) : \Zend\Stdlib\ResponseInterface

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

encodeAuthHeader(string $user, string $password, string $type) : string

see \Zend\Http\http://www.faqs.org/rfcs/rfc2617.html

Parameters

$user

string

$password

string

$type

string

Exceptions

\Zend\Http\Client\Exception\InvalidArgumentException

Returns

string

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

encodeFormData(string $boundary, string $name, mixed $value, string $filename, array $headers) : string

Parameters

$boundary

string

$name

string

$value

mixed

$filename

string

$headers

array

Associative array of optional headers @example ("Content-Transfer-Encoding" => "binary")

Returns

string

Load the connection adapter

getAdapter() : \Zend\Http\Client\Adapter\AdapterInterface

Get the query string argument separator

getArgSeparator() : string

Returns

string

Return the current cookies

getCookies() : array

Returns

array

Get the encoding type

getEncType() : string

Returns

string

Get the header value of the request

getHeader(string $name) : string | bool

Parameters

$name

string

Returns

stringbool

Get the last request (as a string)

getLastRawRequest() : string

Returns

string

Get the last response (as a string)

getLastRawResponse() : string

Returns

string

Get the HTTP method

getMethod() : string

Returns

string

Get the redirections count

getRedirectionsCount() : int

Returns

int

Get Request

getRequest() : \Zend\Http\Request

Get Response

getResponse() : \Zend\Http\Response

Get status of streaming for received data

getStream() : bool | string

Returns

boolstring

Get uri (from the request)

getUri() : \Zend\Uri\Http

Returns

Check if exists the header type specified

hasHeader(string $name) : bool

Parameters

$name

string

Returns

bool

Remove a file to upload

removeFileUpload(string $filename) : bool

Parameters

$filename

string

Returns

bool

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

reset() : \Zend\Http\Client

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

resetParameters(bool $clearCookies) : \Zend\Http\Client

Parameters

$clearCookies

bool

Also clear all valid cookies? (defaults to false)

Returns

Send HTTP request

send(\Zend\Http\Request $request) : \Zend\Http\Response

Load the connection adapter

setAdapter(\Zend\Http\Client\Adapter\AdapterInterface | string $adapter) : \Zend\Http\Client

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

Parameters

Exceptions

\Zend\Http\Client\Exception\InvalidArgumentException

Returns

Set the query string argument separator

setArgSeparator(string $argSeparator) : \Zend\Http\Client

Parameters

$argSeparator

string

Returns

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

setAuth(string $user, string $password, string $type) : \Zend\Http\Client

Parameters

$user

string

$password

string

$type

string

Exceptions

\Zend\Http\Exception\InvalidArgumentException

Returns

Set an array of cookies

setCookies(array $cookies) : \Zend\Http\Client

Parameters

$cookies

array

Exceptions

\Zend\Http\Exception\InvalidArgumentException

Returns

Set the encoding type and the boundary (if any)

setEncType(string $encType, string $boundary) : \Zend\Http\Client

Parameters

$encType

string

$boundary

string

Returns

Set a file to upload (using a POST request)

setFileUpload(string $filename, string $formname, string $data, string $ctype) : \Zend\Http\Client

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.

Parameters

$filename

string

Name of file to upload, or name to save as

$formname

string

Name of form element to send as

$data

string

Data to send (if null, $filename is read and sent)

$ctype

string

Content type to use (if $data is set and $ctype is null, will be application/octet-stream)

Exceptions

\Zend\Http\Exception\RuntimeException

Returns

Set the headers (for the request)

setHeaders(\Zend\Http\Headers | array $headers) : \Zend\Http\Client

Set the HTTP method (to the request)

setMethod(string $method) : \Zend\Http\Client

Parameters

$method

string

Returns

Set configuration parameters for this HTTP client

setOptions(array | \Traversable $options) : \Zend\Http\Client

Parameters

$options

array\Traversable

Exceptions

\Zend\Http\Client\Exception\InvalidArgumentException

Returns

Set the GET parameters

setParameterGet(array $query) : \Zend\Http\Client

Parameters

$query

array

Returns

Set the POST parameters

setParameterPost(array $post) : \Zend\Http\Client

Parameters

$post

array

Returns

Set raw body (for advanced use cases)

setRawBody(string $body) : \Zend\Http\Client

Parameters

$body

string

Returns

Set request

setRequest(\Zend\Http\Request $request) : \Zend\Http\Client

Parameters

Returns

Set response

setResponse(\Zend\Http\Response $response) : \Zend\Http\Client

Parameters

Returns

Set streaming for received data

setStream(string | bool $streamfile) : \Zend\Http\Client

Parameters

$streamfile

stringbool

Stream file, true for temp file, false/null for no streaming

Returns

Set Uri (to the request)

setUri(string | \Zend\Uri\Http $uri) : \Zend\Http\Client

Parameters

$uri

string\Zend\Uri\Http

Returns

Calculate the response value according to the HTTP authentication type

calcAuthDigest(string $user, string $password, string $type, array $digest, null | string $entityBody) : string | bool

see \Zend\Http\http://www.faqs.org/rfcs/rfc2617.html

Parameters

$user

string

$password

string

$type

string

$digest

array

$entityBody

nullstring

Exceptions

\Zend\Http\Exception\InvalidArgumentException

Returns

stringbool

Attempt to detect the MIME type of a file using available extensions

detectFileMimeType(string $file) : string

This method will try to detect the MIME type of a file. If the fileinfo extension is available, it will be used. If not, the mime_magic extension which is deprecated but is still available in many PHP setups will be tried.

If neither extension is available, the default application/octet-stream MIME type will be returned

Parameters

$file

string

File path

Returns

stringMIME type

Separating this from send method allows subclasses to wrap the interaction with the adapter

doRequest(\Zend\Uri\Http $uri, string $method, bool $secure, array $headers, string $body) : string

Parameters

$method

string

$secure

bool

$headers

array

$body

string

Exceptions

\Zend\Http\Exception\RuntimeException

Returns

stringthe raw response

Convert an array of parameters into a flat array of (key, value) pairs

flattenParametersArray(array $parray, string $prefix) : array

Will flatten a potentially multi-dimentional array of parameters (such as POST parameters) into a flat array of (key, value) paris. In case of multi-dimentional arrays, square brackets ([]) will be added to the key to indicate an array.

since 1.9

Parameters

$parray

array

$prefix

string

Returns

array

Get the cookie Id (name+domain+path)

getCookieId(\Zend\Http\Header\SetCookie | \Zend\Http\Header\Cookie $cookie) : string | bool

Parameters

Returns

stringbool

Create temporary stream

openTempStream() : resource

Exceptions

\Zend\Http\Exception\RuntimeException

Returns

resource

Prepare the request body (for PATCH, POST and PUT requests)

prepareBody() : string

Prepare Cookies

prepareCookies(string $domain, string $path, bool $secure) : \Zend\Http\Header\Cookie | bool

Parameters

$domain

string

$path

string

$secure

bool

Returns

Prepare the request headers

prepareHeaders(resource | string $body, \Zend\Uri\Http $uri) : array

Parameters

$body

resourcestring

Exceptions

\Zend\Http\Exception\RuntimeException

Returns

array

 Properties

 

$adapter

$adapter : \Zend\Http\Client/Adapter

 

$auth

$auth : array

 

Configuration array, set using the constructor or using ::setOptions()

$config : array

 

<p>of Header\SetCookie</p>

$cookies : array

 

$encType

$encType : string

 

Fileinfo magic database resource

$fileInfoDb : resource

This variable is populated the first time _detectFileMimeType is called and is then reused on every call to this method

 

$lastRawRequest

$lastRawRequest : \Zend\Http\Request

 

$lastRawResponse

$lastRawResponse : \Zend\Http\Response

 

$redirectCounter

$redirectCounter : int

 

$request

$request : \Zend\Http\Request

 

$response

$response : \Zend\Http\Response

 

$streamName

$streamName : string

 Constants

 

AUTH_BASIC

AUTH_BASIC 

const string Supported HTTP Authentication methods
 

AUTH_DIGEST

AUTH_DIGEST 

 

DIGEST_CNONCE

DIGEST_CNONCE 

 

DIGEST_NC

DIGEST_NC 

 

DIGEST_NONCE

DIGEST_NONCE 

 

DIGEST_OPAQUE

DIGEST_OPAQUE 

 

DIGEST_QOP

DIGEST_QOP 

 

DIGEST_REALM

DIGEST_REALM 

const string DIGEST Authentication
 

ENC_FORMDATA

ENC_FORMDATA 

 

ENC_URLENCODED

ENC_URLENCODED 

const string POST data encoding methods