1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
Класс HttpClient
Граф наследования:HttpClient:
DebugInterface AdsHttpClient

Открытые члены

 __construct (array $options=null)
 get ($url)
 head ($url)
 post ($url, $postData=null, $multipart=false)
 query ($method, $url, $entityBody=null)
 setHeader ($name, $value, $replace=true)
 setHeaders (array $headers)
 getRequestHeaders ()
 clearHeaders ()
 setCookies (array $cookies)
 setAuthorization ($user, $pass)
 setRedirect ($value, $max=null)
 waitResponse ($value)
 setTimeout ($value)
 setStreamTimeout ($value)
 setVersion ($value)
 setCompress ($value)
 setCharset ($value)
 disableSslVerification ()
 setPrivateIp ($value)
 setProxy ($proxyHost, $proxyPort=null, $proxyUser=null, $proxyPassword=null)
 setOutputStream ($handler)
 setBodyLengthMax ($bodyLengthMax)
 download ($url, $filePath, string $method=Http\Method::GET, $entityBody=null)
 saveFile ($filePath)
 getEffectiveUrl ()
 setContextOptions (array $options)
 getHeaders ()
 getCookies ()
 getStatus ()
 getResult ()
 getResponse ()
 getError ()
 getContentType ()
 getCharset ()
 getPeerAddress ()
 sendRequest (RequestInterface $request)
 sendAsyncRequest (RequestInterface $request)
 wait ()
 shouldFetchBody (callable $callback)
 setResponseBuilder (Http\ResponseBuilderInterface $responseBuilder)
Открытые члены унаследованные от DebugInterface
 setDebugLevel (int $debugLevel)
 getDebugLevel ()

Поля данных

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

Защищенные члены

 prepareMultipart ($postData)
 addError ($code, $message, $triggerWarning=false)
 buildRequest (RequestInterface $request)
 checkRequest (RequestInterface $request)
 createHandler (RequestInterface $request, bool $async=false)
 createPromise ($handler, Http\Queue $queue)
 createQueue ()

Защищенные данные

 $proxyHost = ''
 $proxyPort = 80
 $proxyUser = ''
 $proxyPassword = ''
 $socketTimeout = self::DEFAULT_SOCKET_TIMEOUT
 $streamTimeout = self::DEFAULT_STREAM_TIMEOUT
 $waitResponse = true
 $redirect = true
 $redirectMax = 5
 $redirectCount = 0
 $compress = false
 $version = self::HTTP_1_1
 $requestCharset = ''
 $sslVerify = true
 $bodyLengthMax = 0
 $privateIp = true
 $contextOptions = []
 $outputStream = null
 $useCurl = false
 $curlLogFile = null
 $shouldFetchBody = null
 $sendEvents = true
Http ResponseBuilderInterface $responseBuilder
HttpHeaders $headers
Http Request $request = null
Http Response $response = null
Http Queue $queue = null
IpAddress $effectiveIp = null
 $effectiveUrl
 $error = []

Подробное описание

См. определение в файле httpclient.php строка 23

Конструктор(ы)

◆ __construct()

__construct ( array $options = null)
Аргументы
array | null$optionsOptional 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. "sendEvents" bool Send events (default true). "responseBuilder" Http\ResponseBuilderInterface Response builder. Almost all options can be set separately with setters.

См. определение в файле httpclient.php строка 101

Методы

◆ addError()

addError ( $code,
$message,
$triggerWarning = false )
protected

См. определение в файле httpclient.php строка 806

◆ buildRequest()

buildRequest ( RequestInterface $request)
protected

См. определение в файле httpclient.php строка 816

◆ checkRequest()

checkRequest ( RequestInterface $request)
protected

См. определение в файле httpclient.php строка 910

◆ clearHeaders()

clearHeaders ( )

Clears all HTTP request header fields.

См. определение в файле httpclient.php строка 425

◆ createHandler()

createHandler ( RequestInterface $request,
bool $async = false )
protected
Аргументы
RequestInterface$request
bool$async
Возвращает
Http\Curl\Handler | Http\Socket\Handler

См. определение в файле httpclient.php строка 1001

◆ createPromise()

createPromise ( $handler,
Http\Queue $queue )
protected
Аргументы
Http\Curl\Handler  |  Http\Socket\Handler$handler
Http\Queue$queue
Возвращает
Http\Curl\Promise | Http\Socket\Promise

См. определение в файле httpclient.php строка 1056

◆ createQueue()

createQueue ( )
protected
Возвращает
Http\Curl\Queue | Http\Socket\Queue

См. определение в файле httpclient.php строка 1068

◆ disableSslVerification()

disableSslVerification ( )

Disables ssl certificate verification.

Возвращает
$this

См. определение в файле httpclient.php строка 560

◆ download()

download ( $url,
$filePath,
string $method = Http\Method::GET,
$entityBody = null )

Downloads and saves a file.

Аргументы
string$urlURI to download.
string$filePathAbsolute file path.
Возвращает
bool

См. определение в файле httpclient.php строка 635

◆ get()

get ( $url)

Performs GET request.

Аргументы
string$urlAbsolute URI e.g. "http://user:pass @ host:port/path/?query".
Возвращает
string|bool Response entity string or false on error. Note, it's empty string if outputStream is set.

См. определение в файле httpclient.php строка 204

◆ getCharset()

getCharset ( )

Returns response content encoding.

Возвращает
string

См. определение в файле httpclient.php строка 787

◆ getContentType()

getContentType ( )

Returns response content type.

Возвращает
string

См. определение в файле httpclient.php строка 777

◆ getCookies()

getCookies ( )

Returns parsed HTTP response cookies.

Возвращает
HttpCookies

См. определение в файле httpclient.php строка 709

◆ getEffectiveUrl()

getEffectiveUrl ( )

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

Возвращает
string

См. определение в файле httpclient.php строка 673

◆ getError()

getError ( )

Returns array of errors on failure.

Возвращает
array Array with "error_code" => "error_message" pair

См. определение в файле httpclient.php строка 767

◆ getHeaders()

getHeaders ( )

Returns parsed HTTP response headers.

Возвращает
HttpHeaders

См. определение в файле httpclient.php строка 695

◆ getPeerAddress()

getPeerAddress ( )

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

Возвращает
string|false

См. определение в файле httpclient.php строка 797

◆ getRequestHeaders()

getRequestHeaders ( )

Returns HTTP request headers.

Возвращает
HttpHeaders

См. определение в файле httpclient.php строка 413

◆ getResponse()

getResponse ( )

Returns PSR-7 response.

Возвращает
Http\Response|null

См. определение в файле httpclient.php строка 757

◆ getResult()

getResult ( )

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

Возвращает
string

См. определение в файле httpclient.php строка 733

◆ getStatus()

getStatus ( )

Returns HTTP response status code.

Возвращает
int

См. определение в файле httpclient.php строка 719

◆ head()

head ( $url)

Performs HEAD request.

Аргументы
string$urlAbsolute URI e.g. "http://user:pass @ host:port/path/?query"
Возвращает
HttpHeaders|bool Response headers or false on error.

См. определение в файле httpclient.php строка 219

◆ post()

post ( $url,
$postData = null,
$multipart = false )

Performs POST request.

Аргументы
string$urlAbsolute URI e.g. "http://user:pass @ host:port/path/?query".
array | string | resource$postDataEntity of POST/PUT request. If it's resource handler then data will be read directly from the stream.
boolean$multipartWhether 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'
Возвращает
string|bool Response entity string or false on error. Note, it's empty string if outputStream is set.

См. определение в файле httpclient.php строка 236

◆ prepareMultipart()

prepareMultipart ( $postData)
protected

Performs multipart/form-data encoding. Accepts file as a resource or as an array with keys 'resource' (or 'content') and optionally 'filename' and 'contentType'.

Аргументы
array | string | resource$postDataEntity of POST/PUT request
Возвращает
Http\MultipartStream|bool False on error

См. определение в файле httpclient.php строка 261

◆ query()

query ( $method,
$url,
$entityBody = null )

Perfoms HTTP request.

Аргументы
string$methodHTTP method (GET, POST, etc.). Note, it must be in UPPERCASE.
string$urlAbsolute URI e.g. "http://user:pass @ host:port/path/?query".
array | string | resource | Http\Stream$entityBodyEntity body of the request. If it's resource handler then data will be read directly from the stream.
Возвращает
bool Query result (true or false). Response entity string can be got via getResult() method. Note, it's empty string if outputStream is set.

См. определение в файле httpclient.php строка 290

◆ saveFile()

saveFile ( $filePath)

Saves a downloaded file.

Аргументы
string$filePathAbsolute file path.

См. определение в файле httpclient.php строка 654

◆ sendAsyncRequest()

sendAsyncRequest ( RequestInterface $request)
Аргументы
RequestInterface$request
Возвращает
PromiseInterface
Исключения
Http

ClientException

См. определение в файле httpclient.php строка 973

◆ sendRequest()

sendRequest ( RequestInterface $request)

См. определение в файле httpclient.php строка 952

◆ setAuthorization()

setAuthorization ( $user,
$pass )

Sets Basic Authorization request header field.

Аргументы
string$userUsername.
string$passPassword.
Возвращает
$this

См. определение в файле httpclient.php строка 453

◆ setBodyLengthMax()

setBodyLengthMax ( $bodyLengthMax)

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

Аргументы
int$bodyLengthMax
Возвращает
$this

См. определение в файле httpclient.php строка 622

◆ setCharset()

setCharset ( $value)

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

Аргументы
string$valueCharset.
Возвращает
$this

См. определение в файле httpclient.php строка 549

◆ setCompress()

setCompress ( $value)

Sets compression option. 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

Аргументы
bool$valueIf true, "Accept-Encoding: gzip" will be sent.
Возвращает
$this

См. определение в файле httpclient.php строка 537

◆ setContextOptions()

setContextOptions ( array $options)

Sets context options and parameters.

Аргументы
array$optionsContext options and parameters
Возвращает
$this

См. определение в файле httpclient.php строка 684

◆ setCookies()

setCookies ( array $cookies)

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

Аргументы
array$cookiesArray of cookie_name => value pairs.
Возвращает
$this

См. определение в файле httpclient.php строка 436

◆ setHeader()

setHeader ( $name,
$value,
$replace = true )

Sets an HTTP request header.

Аргументы
string$nameName of the header field.
string$valueValue of the field.
bool$replaceReplace existing header field with the same name or add one more.
Возвращает
$this

См. определение в файле httpclient.php строка 384

◆ setHeaders()

setHeaders ( array $headers)

Sets an array of headers for HTTP request.

Аргументы
array$headersArray of header_name => value pairs.
Возвращает
$this

См. определение в файле httpclient.php строка 399

◆ setOutputStream()

setOutputStream ( $handler)

Sets the response output to the stream instead of the string result. Useful for large responses. 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.

Аргументы
resource$handlerFile or stream handler.
Возвращает
$this

См. определение в файле httpclient.php строка 610

◆ setPrivateIp()

setPrivateIp ( $value)

Enables or disables requests to private IPs.

Аргументы
bool$value
Возвращает
$this

См. определение в файле httpclient.php строка 572

◆ setProxy()

setProxy ( $proxyHost,
$proxyPort = null,
$proxyUser = null,
$proxyPassword = null )

Sets HTTP proxy for request.

Аргументы
string$proxyHostProxy host name or address (without "http://").
null | int$proxyPortProxy port number.
null | string$proxyUserProxy username.
null | string$proxyPasswordProxy password.
Возвращает
$this

См. определение в файле httpclient.php строка 587

◆ setRedirect()

setRedirect ( $value,
$max = null )

Sets redirect options.

Аргументы
bool$valueIf true, do redirect (default true).
null | int$maxMaximum allowed redirect count.
Возвращает
$this

См. определение в файле httpclient.php строка 466

◆ setResponseBuilder()

setResponseBuilder ( Http\ResponseBuilderInterface $responseBuilder)

Sets a builder for a response.

Аргументы
Http\ResponseBuilderInterface$responseBuilder
Возвращает
$this

См. определение в файле httpclient.php строка 1115

◆ setStreamTimeout()

setStreamTimeout ( $value)

Sets socket stream reading timeout.

Аргументы
int$valueStream reading timeout in seconds; "0" means no timeout (default 60).
Возвращает
$this

См. определение в файле httpclient.php строка 511

◆ setTimeout()

setTimeout ( $value)

Sets connection timeout.

Аргументы
int$valueConnection timeout in seconds (default 30).
Возвращает
$this

См. определение в файле httpclient.php строка 499

◆ setVersion()

setVersion ( $value)

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

Аргументы
string$valueVersion "1.0" or "1.1" (default "1.0").
Возвращает
$this

См. определение в файле httpclient.php строка 523

◆ shouldFetchBody()

shouldFetchBody ( callable $callback)

Sets a callback called before fetching a message body.

Аргументы
callable$callback
Возвращает
$this

См. определение в файле httpclient.php строка 1103

◆ wait()

wait ( )

Waits for async promises and returns responses from processed promises.

Возвращает
ResponseInterface[]

См. определение в файле httpclient.php строка 1082

◆ waitResponse()

waitResponse ( $value)

Sets response body waiting option.

Аргументы
bool$valueIf true, wait for response body. If false, disconnect just after reading headers (default true).
Возвращает
$this

См. определение в файле httpclient.php строка 482

Поля

◆ $bodyLengthMax

$bodyLengthMax = 0
protected

См. определение в файле httpclient.php строка 57

◆ $compress

$compress = false
protected

См. определение в файле httpclient.php строка 53

◆ $contextOptions

$contextOptions = []
protected

См. определение в файле httpclient.php строка 59

◆ $curlLogFile

$curlLogFile = null
protected

См. определение в файле httpclient.php строка 62

◆ $effectiveIp

IpAddress $effectiveIp = null
protected

См. определение в файле httpclient.php строка 71

◆ $effectiveUrl

$effectiveUrl
protected

См. определение в файле httpclient.php строка 72

◆ $error

$error = []
protected

См. определение в файле httpclient.php строка 73

◆ $headers

HttpHeaders $headers
protected

См. определение в файле httpclient.php строка 67

◆ $outputStream

$outputStream = null
protected

См. определение в файле httpclient.php строка 60

◆ $privateIp

$privateIp = true
protected

См. определение в файле httpclient.php строка 58

◆ $proxyHost

$proxyHost = ''
protected

См. определение в файле httpclient.php строка 43

◆ $proxyPassword

$proxyPassword = ''
protected

См. определение в файле httpclient.php строка 46

◆ $proxyPort

$proxyPort = 80
protected

См. определение в файле httpclient.php строка 44

◆ $proxyUser

$proxyUser = ''
protected

См. определение в файле httpclient.php строка 45

◆ $queue

Http Queue $queue = null
protected

См. определение в файле httpclient.php строка 70

◆ $redirect

$redirect = true
protected

См. определение в файле httpclient.php строка 50

◆ $redirectCount

$redirectCount = 0
protected

См. определение в файле httpclient.php строка 52

◆ $redirectMax

$redirectMax = 5
protected

См. определение в файле httpclient.php строка 51

◆ $request

Http Request $request = null
protected

См. определение в файле httpclient.php строка 68

◆ $requestCharset

$requestCharset = ''
protected

См. определение в файле httpclient.php строка 55

◆ $response

Http Response $response = null
protected

См. определение в файле httpclient.php строка 69

◆ $responseBuilder

Http ResponseBuilderInterface $responseBuilder
protected

См. определение в файле httpclient.php строка 65

◆ $sendEvents

$sendEvents = true
protected

См. определение в файле httpclient.php строка 64

◆ $shouldFetchBody

$shouldFetchBody = null
protected

См. определение в файле httpclient.php строка 63

◆ $socketTimeout

$socketTimeout = self::DEFAULT_SOCKET_TIMEOUT
protected

См. определение в файле httpclient.php строка 47

◆ $sslVerify

$sslVerify = true
protected

См. определение в файле httpclient.php строка 56

◆ $streamTimeout

$streamTimeout = self::DEFAULT_STREAM_TIMEOUT
protected

См. определение в файле httpclient.php строка 48

◆ $useCurl

$useCurl = false
protected

См. определение в файле httpclient.php строка 61

◆ $version

$version = self::HTTP_1_1
protected

См. определение в файле httpclient.php строка 54

◆ $waitResponse

$waitResponse = true
protected

См. определение в файле httpclient.php строка 49

◆ DEFAULT_SOCKET_TIMEOUT

const DEFAULT_SOCKET_TIMEOUT = 30

См. определение в файле httpclient.php строка 39

◆ DEFAULT_STREAM_TIMEOUT

const DEFAULT_STREAM_TIMEOUT = 60

См. определение в файле httpclient.php строка 40

◆ DEFAULT_STREAM_TIMEOUT_NO_WAIT

const DEFAULT_STREAM_TIMEOUT_NO_WAIT = 1

См. определение в файле httpclient.php строка 41

◆ HTTP_1_0

const HTTP_1_0 = '1.0'

См. определение в файле httpclient.php строка 28

◆ HTTP_1_1

const HTTP_1_1 = '1.1'

См. определение в файле httpclient.php строка 29

◆ HTTP_DELETE

const HTTP_DELETE = 'DELETE'

См. определение в файле httpclient.php строка 36

◆ HTTP_GET

const HTTP_GET = 'GET'

См. определение в файле httpclient.php строка 31

◆ HTTP_HEAD

const HTTP_HEAD = 'HEAD'

См. определение в файле httpclient.php строка 34

◆ HTTP_OPTIONS

const HTTP_OPTIONS = 'OPTIONS'

См. определение в файле httpclient.php строка 37

◆ HTTP_PATCH

const HTTP_PATCH = 'PATCH'

См. определение в файле httpclient.php строка 35

◆ HTTP_POST

const HTTP_POST = 'POST'

См. определение в файле httpclient.php строка 32

◆ HTTP_PUT

const HTTP_PUT = 'PUT'

См. определение в файле httpclient.php строка 33


Объявления и описания членов класса находятся в файле: