987. Class

987.1. Zend\Http\Client

Http client

987.1.1. Methods

987.1.1.1. __construct

__construct()

Constructor

Parameters:
  • string
  • array|Traversable

987.1.1.2. setOptions

setOptions()

Set configuration parameters for this HTTP client

Parameters:array|Traversable
Return type:Client
Throws :ClientExceptionInvalidArgumentException

987.1.1.3. setAdapter

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

Parameters:ClientAdapterAdapterInterface|string
Return type:Client
Throws :ClientExceptionInvalidArgumentException

987.1.1.4. getAdapter

getAdapter()

Load the connection adapter

Return type:ClientAdapterAdapterInterface $adapter

987.1.1.5. setRequest

setRequest()

Set request

Parameters:Request
Return type:Client

987.1.1.6. getRequest

getRequest()

Get Request

Return type:Request

987.1.1.7. setResponse

setResponse()

Set response

Parameters:Response
Return type:Client

987.1.1.8. getResponse

getResponse()

Get Response

Return type:Response

987.1.1.9. getLastRawRequest

getLastRawRequest()

Get the last request (as a string)

Return type:string

987.1.1.10. getLastRawResponse

getLastRawResponse()

Get the last response (as a string)

Return type:string

987.1.1.11. getRedirectionsCount

getRedirectionsCount()

Get the redirections count

Return type:integer

987.1.1.12. setUri

setUri()

Set Uri (to the request)

Parameters:string|Http
Return type:Client

987.1.1.13. getUri

getUri()

Get uri (from the request)

Return type:Http

987.1.1.14. setMethod

setMethod()

Set the HTTP method (to the request)

Parameters:string
Return type:Client

987.1.1.15. getMethod

getMethod()

Get the HTTP method

Return type:string

987.1.1.16. setArgSeparator

setArgSeparator()

Set the query string argument separator

Parameters:string
Return type:Client

987.1.1.17. getArgSeparator

getArgSeparator()

Get the query string argument separator

Return type:string

987.1.1.18. setEncType

setEncType()

Set the encoding type and the boundary (if any)

Parameters:
  • string
  • string
Return type:

Client

987.1.1.19. getEncType

getEncType()

Get the encoding type

Return type:string

987.1.1.20. setRawBody

setRawBody()

Set raw body (for advanced use cases)

Parameters:string
Return type:Client

987.1.1.21. setParameterPost

setParameterPost()

Set the POST parameters

Parameters:array
Return type:Client

987.1.1.22. setParameterGet

setParameterGet()

Set the GET parameters

Parameters:array
Return type:Client

987.1.1.23. getCookies

getCookies()

Return the current cookies

Return type:array

987.1.1.24. getCookieId

getCookieId()

Get the cookie Id (name+domain+path)

Parameters:HeaderSetCookie|HeaderCookie
Return type:string|bool

987.1.1.25. addCookie

addCookie()

Add a cookie

Parameters:
  • array|ArrayIterator|HeaderSetCookie|string
  • string
  • string
  • string
  • string
  • bool
  • bool
  • string
  • string
Throws ExceptionInvalidArgumentException:
 
Return type:

Client

987.1.1.26. setCookies

setCookies()

Set an array of cookies

Parameters:array
Throws ExceptionInvalidArgumentException:
 
Return type:Client

987.1.1.27. clearCookies

clearCookies()

Clear all the cookies

987.1.1.28. setHeaders

setHeaders()

Set the headers (for the request)

Parameters:Headers|array
Throws ExceptionInvalidArgumentException:
 
Return type:Client

987.1.1.29. hasHeader

hasHeader()

Check if exists the header type specified

Parameters:string
Return type:bool

987.1.1.30. getHeader

getHeader()

Get the header value of the request

Parameters:string
Return type:string|bool

987.1.1.31. setStream

setStream()

Set streaming for received data

Parameters:string|bool – Stream file, true for temp file, false/null for no streaming
Return type:ZendHttpClient

987.1.1.32. getStream

getStream()

Get status of streaming for received data

Return type:bool|string

987.1.1.33. openTempStream

openTempStream()

Create temporary stream

Return type:resource

987.1.1.34. setAuth

setAuth()

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

Parameters:
  • string
  • string
  • string
Throws ExceptionInvalidArgumentException:
 
Return type:

Client

987.1.1.35. calcAuthDigest

calcAuthDigest()

Calculate the response value according to the HTTP authentication type

Parameters:
  • string
  • string
  • string
  • array
  • null|string
Throws ExceptionInvalidArgumentException:
 
Return type:

string|bool

987.1.1.36. resetParameters

resetParameters()

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

Parameters:bool – Also clear all valid cookies? (defaults to false)
Return type:Client

987.1.1.37. dispatch

dispatch()

Dispatch

Parameters:
  • StdlibRequestInterface
  • StdlibResponseInterface
Return type:

StdlibResponseInterface

987.1.1.38. send

send()

Send HTTP request

Parameters:Request
Return type:Response
Throws :ExceptionRuntimeException
Throws :ClientExceptionRuntimeException

987.1.1.39. setFileUpload

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.

Parameters:
  • string – Name of file to upload, or name to save as
  • string – Name of form element to send as
  • string – Data to send (if null, $filename is read and sent)
  • string – Content type to use (if $data is set and $ctype is null, will be application/octet-stream)
Return type:

Client

Throws :

ExceptionRuntimeException

987.1.1.40. removeFileUpload

removeFileUpload()

Remove a file to upload

Parameters:string
Return type:bool

987.1.1.41. prepareCookies

prepareCookies()

Prepare Cookies

Parameters:
  • string
  • string
  • boolean
Return type:

HeaderCookie|bool

987.1.1.42. prepareHeaders

prepareHeaders()

Prepare the request headers

Parameters:
  • resource|string
  • Http
Throws ExceptionRuntimeException:
 
Return type:

array

987.1.1.43. prepareBody

prepareBody()

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

Return type:string
Throws :ZendHttpClientExceptionRuntimeException

987.1.1.44. detectFileMimeType

detectFileMimeType()

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

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:string – File path
Return type:string MIME type

987.1.1.45. encodeFormData

encodeFormData()

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

Parameters:
  • string
  • string
  • mixed
  • string
  • array – Associative array of optional headers @example (“Content-Transfer-Encoding” => “binary”)
Return type:

string

987.1.1.46. flattenParametersArray

flattenParametersArray()

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

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.

Parameters:
  • array
  • string
Return type:

array

987.1.1.47. doRequest

doRequest()

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

Parameters:
  • Http
  • string
  • bool
  • array
  • string
Return type:

string the raw response

Throws :

ExceptionRuntimeException

987.1.1.48. encodeAuthHeader

encodeAuthHeader()

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

Parameters:
  • string
  • string
  • string
Return type:

string

Throws :

ZendHttpClientExceptionInvalidArgumentException

987.1.2. Constants

987.1.2.1. AUTH_BASIC

@const string Supported HTTP Authentication methods

987.1.2.2. AUTH_DIGEST

987.1.2.3. ENC_URLENCODED

@const string POST data encoding methods

987.1.2.4. ENC_FORMDATA

987.1.2.5. DIGEST_REALM

@const string DIGEST Authentication

987.1.2.6. DIGEST_QOP

987.1.2.7. DIGEST_NONCE

987.1.2.8. DIGEST_OPAQUE

987.1.2.9. DIGEST_NC

987.1.2.10. DIGEST_CNONCE

Project Versions

Table Of Contents

Previous topic

986. Class

Next topic

988. Class

This Page