Bitrix API

AdsHttpClient extends HttpClient

Table of Contents

Constants

DEFAULT_SOCKET_TIMEOUT  = 30
DEFAULT_STREAM_TIMEOUT  = 60
DEFAULT_STREAM_TIMEOUT_NO_WAIT  = 1
HTTP_1_0  = '1.0'
HTTP_1_1  = '1.1'
HTTP_DELETE  = "DELETE"
HTTP_GET  = 'GET'
HTTP_HEAD  = 'HEAD'
HTTP_OPTIONS  = 'OPTIONS'
HTTP_PATCH  = 'PATCH'
HTTP_POST  = 'POST'
HTTP_PUT  = 'PUT'

Methods

__construct()  : mixed
clearHeaders()  : mixed
Clears all HTTP request header fields.
delete()  : mixed
disableSslVerification()  : $this
Disables ssl certificate verification.
download()  : bool
Downloads and saves a file.
get()  : string|bool
Performs GET request.
getCharset()  : string
Returns response content encoding.
getContentType()  : string
Returns response content type.
getCookies()  : HttpCookies
Returns parsed HTTP response cookies.
getDebugLevel()  : int
Returns the current level.
getEffectiveUrl()  : string
Returns URL of the last redirect if request was redirected, or initial URL if request was not redirected.
getError()  : array<string|int, mixed>
Returns array of errors on failure.
getHeaders()  : HttpHeaders
Returns parsed HTTP response headers.
getPeerAddress()  : string|false
Returns remote peer ip address (only if privateIp = false).
getRequestHeaders()  : HttpHeaders
Returns HTTP request headers.
getResponse()  : Response|null
Returns PSR-7 response.
getResult()  : string
Returns HTTP response entity string. Note, if outputStream is set, the result will be the empty string.
getStatus()  : int
Returns HTTP response status code.
head()  : HttpHeaders|bool
Performs HEAD request.
post()  : string|bool
Performs POST request.
query()  : bool
Perfoms HTTP request.
saveFile()  : mixed
Saves a downloaded file.
sendAsyncRequest()  : Promise
sendRequest()  : ResponseInterface
setAuthorization()  : $this
Sets Basic Authorization request header field.
setBodyLengthMax()  : $this
Sets the maximum body length that will be received in $this->readBody().
setCharset()  : $this
Sets charset for the entity-body (used in the Content-Type request header field for POST and PUT).
setCompress()  : $this
Sets compression option.
setContextOptions()  : $this
Sets context options and parameters.
setCookies()  : $this
Sets an array of cookies for HTTP request. Warning! Replaces 'Cookie' header.
setDebugLevel()  : mixed
Sets debug level using HttpDebug::* constants.
setHeader()  : $this
Sets an HTTP request header.
setHeaders()  : $this
Sets an array of headers for HTTP request.
setOutputStream()  : $this
Sets the response output to the stream instead of the string result. Useful for large responses.
setPrivateIp()  : $this
Enables or disables requests to private IPs.
setProxy()  : $this
Sets HTTP proxy for request.
setRedirect()  : $this
Sets redirect options.
setResponseBuilder()  : $this
Sets a builder for a response.
setStreamTimeout()  : $this
Sets socket stream reading timeout.
setTimeout()  : $this
Sets connection timeout.
setVersion()  : $this
Sets HTTP protocol version. In version 1.1 chunked response is possible.
shouldFetchBody()  : $this
Sets a callback called before fetching a message body.
wait()  : array<string|int, ResponseInterface>
Waits for async promises and returns responses from processed promises.
waitResponse()  : $this
Sets response body waiting option.

Constants

DEFAULT_SOCKET_TIMEOUT

public mixed DEFAULT_SOCKET_TIMEOUT = 30

DEFAULT_STREAM_TIMEOUT

public mixed DEFAULT_STREAM_TIMEOUT = 60

DEFAULT_STREAM_TIMEOUT_NO_WAIT

public mixed DEFAULT_STREAM_TIMEOUT_NO_WAIT = 1

HTTP_OPTIONS

public mixed HTTP_OPTIONS = 'OPTIONS'

Methods

__construct()

public __construct([array<string|int, mixed>|null $options = null ]) : mixed
Parameters
$options : array<string|int, mixed>|null = null

Optional array with options: "redirect" bool Follow redirects (default true). "redirectMax" int Maximum number of redirects (default 5). "waitResponse" bool Read the body or disconnect just after reading headers (default true). "socketTimeout" int Connection timeout in seconds (default 30). "streamTimeout" int Stream reading timeout in seconds (default 60 for waitResponse == true and 1 for waitResponse == false). "version" string HTTP version (HttpClient::HTTP_1_0, HttpClient::HTTP_1_1) (default "1.1"). "proxyHost" string Proxy host name/address. "proxyPort" int Proxy port number. "proxyUser" string Proxy username. "proxyPassword" string Proxy password. "compress" bool Accept gzip encoding (default false). "charset" string Charset for body in POST and PUT. "disableSslVerification" bool Pass true to disable ssl check. "bodyLengthMax" int Maximum length of the body. "privateIp" bool Enable or disable requests to private IPs (default true). "debugLevel" int Debug level using HttpDebug::* constants. "cookies" array of cookies for HTTP request. "headers" array of headers for HTTP request. "useCurl" bool Enable CURL (default false). "curlLogFile" string Full path to CURL log file. "responseBuilder" Http\ResponseBuilderInterface Response builder. Almost all options can be set separately with setters.

clearHeaders()

Clears all HTTP request header fields.

public clearHeaders() : mixed

delete()

public delete(mixed $url[, mixed $postData = null ][, mixed $multipart = false ]) : mixed
Parameters
$url : mixed
$postData : mixed = null
$multipart : mixed = false

disableSslVerification()

Disables ssl certificate verification.

public disableSslVerification() : $this
Return values
$this

download()

Downloads and saves a file.

public download(string $url, string $filePath[, string $method = HttpMethod::GET ][, mixed $entityBody = null ]) : bool
Parameters
$url : string

URI to download.

$filePath : string

Absolute file path.

$method : string = HttpMethod::GET
$entityBody : mixed = null
Return values
bool

get()

Performs GET request.

public get(string $url) : string|bool
Parameters
$url : string

Absolute URI e.g. "http://user:pass @ host:port/path/?query".

Return values
string|bool

Response entity string or false on error. Note, it's empty string if outputStream is set.

getCharset()

Returns response content encoding.

public getCharset() : string
Return values
string

getContentType()

Returns response content type.

public getContentType() : string
Return values
string

getDebugLevel()

Returns the current level.

public getDebugLevel() : int
Return values
int

HttpDebug::* constants

getEffectiveUrl()

Returns URL of the last redirect if request was redirected, or initial URL if request was not redirected.

public getEffectiveUrl() : string
Return values
string

getError()

Returns array of errors on failure.

public getError() : array<string|int, mixed>
Return values
array<string|int, mixed>

Array with "error_code" => "error_message" pair

getPeerAddress()

Returns remote peer ip address (only if privateIp = false).

public getPeerAddress() : string|false
Return values
string|false

getResult()

Returns HTTP response entity string. Note, if outputStream is set, the result will be the empty string.

public getResult() : string
Return values
string

getStatus()

Returns HTTP response status code.

public getStatus() : int
Return values
int

head()

Performs HEAD request.

public head(string $url) : HttpHeaders|bool
Parameters
$url : string

Absolute URI e.g. "http://user:pass @ host:port/path/?query"

Return values
HttpHeaders|bool

Response headers or false on error.

post()

Performs POST request.

public post(string $url[, array<string|int, mixed>|string|resource $postData = null ][, bool $multipart = false ]) : string|bool
Parameters
$url : string

Absolute URI e.g. "http://user:pass @ host:port/path/?query".

$postData : array<string|int, mixed>|string|resource = null

Entity of POST/PUT request. If it's resource handler then data will be read directly from the stream.

$multipart : bool = false

Whether to use multipart/form-data encoding. If true, method accepts file as a resource or as an array with keys 'resource' (or 'content') and optionally 'filename' and 'contentType'

Return values
string|bool

Response entity string or false on error. Note, it's empty string if outputStream is set.

query()

Perfoms HTTP request.

public query(string $method, string $url[, array<string|int, mixed>|string|resource|Stream $entityBody = null ]) : bool
Parameters
$method : string

HTTP method (GET, POST, etc.). Note, it must be in UPPERCASE.

$url : string

Absolute URI e.g. "http://user:pass @ host:port/path/?query".

$entityBody : array<string|int, mixed>|string|resource|Stream = null

Entity body of the request. If it's resource handler then data will be read directly from the stream.

Return values
bool

Query result (true or false). Response entity string can be got via getResult() method. Note, it's empty string if outputStream is set.

saveFile()

Saves a downloaded file.

public saveFile(string $filePath) : mixed
Parameters
$filePath : string

Absolute file path.

sendAsyncRequest()

public sendAsyncRequest(RequestInterface $request) : Promise
Parameters
$request : RequestInterface
Tags
throws
ClientException
Return values
Promise

sendRequest()

public sendRequest(RequestInterface $request) : ResponseInterface
Parameters
$request : RequestInterface
Tags
inheritdoc
Return values
ResponseInterface

setAuthorization()

Sets Basic Authorization request header field.

public setAuthorization(string $user, string $pass) : $this
Parameters
$user : string

Username.

$pass : string

Password.

Return values
$this

setBodyLengthMax()

Sets the maximum body length that will be received in $this->readBody().

public setBodyLengthMax(int $bodyLengthMax) : $this
Parameters
$bodyLengthMax : int
Return values
$this

setCharset()

Sets charset for the entity-body (used in the Content-Type request header field for POST and PUT).

public setCharset(string $value) : $this
Parameters
$value : string

Charset.

Return values
$this

setCompress()

Sets compression option.

public setCompress(bool $value) : $this

Consider not to use the "compress" option with the output stream if a content can be large. Note, that compressed response is processed anyway if Content-Encoding response header field is set

Parameters
$value : bool

If true, "Accept-Encoding: gzip" will be sent.

Return values
$this

setContextOptions()

Sets context options and parameters.

public setContextOptions(array<string|int, mixed> $options) : $this
Parameters
$options : array<string|int, mixed>

Context options and parameters

Return values
$this

setCookies()

Sets an array of cookies for HTTP request. Warning! Replaces 'Cookie' header.

public setCookies(array<string|int, mixed> $cookies) : $this
Parameters
$cookies : array<string|int, mixed>

Array of cookie_name => value pairs.

Return values
$this

setDebugLevel()

Sets debug level using HttpDebug::* constants.

public setDebugLevel(int $debugLevel) : mixed
Parameters
$debugLevel : int

setHeader()

Sets an HTTP request header.

public setHeader(string $name, string $value[, bool $replace = true ]) : $this
Parameters
$name : string

Name of the header field.

$value : string

Value of the field.

$replace : bool = true

Replace existing header field with the same name or add one more.

Return values
$this

setHeaders()

Sets an array of headers for HTTP request.

public setHeaders(array<string|int, mixed> $headers) : $this
Parameters
$headers : array<string|int, mixed>

Array of header_name => value pairs.

Return values
$this

setOutputStream()

Sets the response output to the stream instead of the string result. Useful for large responses.

public setOutputStream(resource $handler) : $this

Note, the stream must be readable/writable to support a compressed response. Note, in this mode the result string is empty. Note, only Http\Stream response body is supported.

Parameters
$handler : resource

File or stream handler.

Return values
$this

setPrivateIp()

Enables or disables requests to private IPs.

public setPrivateIp(bool $value) : $this
Parameters
$value : bool
Return values
$this

setProxy()

Sets HTTP proxy for request.

public setProxy(string $proxyHost[, null|int $proxyPort = null ][, null|string $proxyUser = null ][, null|string $proxyPassword = null ]) : $this
Parameters
$proxyHost : string

Proxy host name or address (without "http://").

$proxyPort : null|int = null

Proxy port number.

$proxyUser : null|string = null

Proxy username.

$proxyPassword : null|string = null

Proxy password.

Return values
$this

setRedirect()

Sets redirect options.

public setRedirect(bool $value[, null|int $max = null ]) : $this
Parameters
$value : bool

If true, do redirect (default true).

$max : null|int = null

Maximum allowed redirect count.

Return values
$this

setStreamTimeout()

Sets socket stream reading timeout.

public setStreamTimeout(int $value) : $this
Parameters
$value : int

Stream reading timeout in seconds; "0" means no timeout (default 60).

Return values
$this

setTimeout()

Sets connection timeout.

public setTimeout(int $value) : $this
Parameters
$value : int

Connection timeout in seconds (default 30).

Return values
$this

setVersion()

Sets HTTP protocol version. In version 1.1 chunked response is possible.

public setVersion(string $value) : $this
Parameters
$value : string

Version "1.0" or "1.1" (default "1.0").

Return values
$this

shouldFetchBody()

Sets a callback called before fetching a message body.

public shouldFetchBody(callable $callback) : $this
Parameters
$callback : callable
Return values
$this

wait()

Waits for async promises and returns responses from processed promises.

public wait() : array<string|int, ResponseInterface>
Return values
array<string|int, ResponseInterface>

waitResponse()

Sets response body waiting option.

public waitResponse(bool $value) : $this
Parameters
$value : bool

If true, wait for response body. If false, disconnect just after reading headers (default true).

Return values
$this

        
On this page

Search results