Bitrix-D7 22.6
 
Загрузка...
Поиск...
Не найдено
Класс HttpClient
+ Граф наследования:HttpClient:

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

 __construct (array $options=null)
 
 __destruct ()
 
 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)
 
 getEffectiveUrl ()
 
 setContextOptions (array $options)
 
 getHeaders ()
 
 getCookies ()
 
 getStatus ()
 
 getResult ()
 
 getError ()
 
 getContentType ()
 
 getCharset ()
 
 getPeerSocketName ()
 
 getPeerAddress ()
 
 getPeerPort ()
 
 setDebugLevel (int $debugLevel)
 

Открытые атрибуты

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
 
const BUF_READ_LEN = 16384
 
const BUF_POST_LEN = 131072
 

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

 prepareMultipart ($postData)
 
 connect (Uri $url)
 
 createContext ()
 
 disconnect ()
 
 send ($data)
 
 receive ($bufLength=null)
 
 sendRequest ($method, Uri $url, $entityBody=null)
 
 readHeaders ()
 
 readBody ()
 
 receiveBytes ($length)
 
 checkErrors ($buf)
 
 decompress ()
 
 parseHeaders ($headers)
 
 addError ($code, $message, $triggerWarning=false)
 
 getLogger ()
 

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

 $proxyHost
 
 $proxyPort
 
 $proxyUser
 
 $proxyPassword
 
 $resource
 
 $socketTimeout = self::DEFAULT_SOCKET_TIMEOUT
 
 $streamTimeout = self::DEFAULT_STREAM_TIMEOUT
 
 $error = []
 
 $peerSocketName
 
 $requestHeaders
 
 $requestCookies
 
 $waitResponse = true
 
 $redirect = true
 
 $redirectMax = 5
 
 $redirectCount = 0
 
 $compress = false
 
 $version = self::HTTP_1_0
 
 $requestCharset = ''
 
 $sslVerify = true
 
 $bodyLengthMax = 0
 
 $privateIp = true
 
 $status = 0
 
 $responseHeaders
 
 $responseCookies
 
 $result = ''
 
 $outputStream
 
 $effectiveIp
 
 $effectiveUrl
 
 $queryMethod
 
 $receivedBytesLength = 0
 
 $contextOptions = []
 
 $debugLevel = HttpDebug::REQUEST_HEADERS | HttpDebug::RESPONSE_HEADERS
 

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

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

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

◆ __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.0"). "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. All the options can be set separately with setters.

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

◆ __destruct()

__destruct ( )

Closes the connection on the object destruction.

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

Методы

◆ addError()

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

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

◆ checkErrors()

checkErrors (   $buf)
protected

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

◆ clearHeaders()

clearHeaders ( )

Clears all HTTP request header fields.

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

◆ connect()

connect ( Uri  $url)
protected

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

◆ createContext()

createContext ( )
protected

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

◆ decompress()

decompress ( )
protected

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

◆ disableSslVerification()

disableSslVerification ( )

Disables ssl certificate verification.

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

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

◆ disconnect()

disconnect ( )
protected

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

◆ download()

download (   $url,
  $filePath 
)

Downloads and saves a file.

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

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

◆ get()

get (   $url)

Performs GET request.

Аргументы
string$urlAbsolute URI eg. "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 строка 194

◆ getCharset()

getCharset ( )

Returns response content encoding

Возвращает
string

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

◆ getContentType()

getContentType ( )

Returns response content type

Возвращает
string

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

◆ getCookies()

getCookies ( )

Returns parsed HTTP response cookies

Возвращает
HttpCookies

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

◆ getEffectiveUrl()

getEffectiveUrl ( )

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

Возвращает
string

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

◆ getError()

getError ( )

Returns array of errors on failure

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

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

◆ getHeaders()

getHeaders ( )

Returns parsed HTTP response headers

Возвращает
HttpHeaders

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

◆ getLogger()

getLogger ( )
protected

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

◆ getPeerAddress()

getPeerAddress ( )

Returns remote peer ip address.

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

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

◆ getPeerPort()

getPeerPort ( )

Returns remote peer ip address.

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

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

◆ getPeerSocketName()

getPeerSocketName ( )

Returns remote peer socket name (usually in form ip:port)

Возвращает
string

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

◆ getRequestHeaders()

getRequestHeaders ( )

Returns HTTP request headers.

Возвращает
HttpHeaders

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

◆ getResult()

getResult ( )

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

Возвращает
string

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

◆ getStatus()

getStatus ( )

Returns HTTP response status code

Возвращает
int

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

◆ head()

head (   $url)

Performs HEAD request.

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

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

◆ parseHeaders()

parseHeaders (   $headers)
protected

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

◆ post()

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

Performs POST request.

Аргументы
string$urlAbsolute URI eg. "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 строка 226

◆ 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
Возвращает
string|bool False on error

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

◆ query()

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

Perfoms HTTP request.

Аргументы
string$methodHTTP method (GET, POST, etc.). Note, it must be in UPPERCASE.
string$urlAbsolute URI eg. "http://user:pass @ host:port/path/?query".
array | string | resource$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 строка 331

◆ readBody()

readBody ( )
protected

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

◆ readHeaders()

readHeaders ( )
protected

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

◆ receive()

receive (   $bufLength = null)
protected

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

◆ receiveBytes()

receiveBytes (   $length)
protected

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

◆ send()

send (   $data)
protected

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

◆ sendRequest()

sendRequest (   $method,
Uri  $url,
  $entityBody = null 
)
protected

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

◆ setAuthorization()

setAuthorization (   $user,
  $pass 
)

Sets Basic Authorization request header field.

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

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

◆ setBodyLengthMax()

setBodyLengthMax (   $bodyLengthMax)

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

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

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

◆ 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 строка 591

◆ 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 строка 579

◆ setContextOptions()

setContextOptions ( array  $options)

Sets context options and parameters.

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

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

◆ setCookies()

setCookies ( array  $cookies)

Sets an array of cookies for HTTP request.

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

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

◆ setDebugLevel()

setDebugLevel ( int  $debugLevel)

Sets debug level using HttpDebug::* constants.

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

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

◆ setHeader()

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

Sets an HTTP request header field.

Аргументы
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 строка 434

◆ setHeaders()

setHeaders ( array  $headers)

Sets an array of headers for HTTP request.

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

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

◆ 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.

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

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

◆ setPrivateIp()

setPrivateIp (   $value)

Enables or disables requests to private IPs.

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

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

◆ 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 строка 629

◆ setRedirect()

setRedirect (   $value,
  $max = null 
)

Sets redirect options.

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

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

◆ setStreamTimeout()

setStreamTimeout (   $value)

Sets socket stream reading timeout.

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

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

◆ setTimeout()

setTimeout (   $value)

Sets connection timeout.

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

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

◆ 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 строка 565

◆ 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 строка 524

Данные класса

◆ $bodyLengthMax

$bodyLengthMax = 0
protected

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

◆ $compress

$compress = false
protected

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

◆ $contextOptions

$contextOptions = []
protected

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

◆ $debugLevel

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

◆ $effectiveIp

$effectiveIp
protected

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

◆ $effectiveUrl

$effectiveUrl
protected

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

◆ $error

$error = []
protected

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

◆ $outputStream

$outputStream
protected

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

◆ $peerSocketName

$peerSocketName
protected

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

◆ $privateIp

$privateIp = true
protected

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

◆ $proxyHost

$proxyHost
protected

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

◆ $proxyPassword

$proxyPassword
protected

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

◆ $proxyPort

$proxyPort
protected

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

◆ $proxyUser

$proxyUser
protected

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

◆ $queryMethod

$queryMethod
protected

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

◆ $receivedBytesLength

$receivedBytesLength = 0
protected

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

◆ $redirect

$redirect = true
protected

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

◆ $redirectCount

$redirectCount = 0
protected

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

◆ $redirectMax

$redirectMax = 5
protected

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

◆ $requestCharset

$requestCharset = ''
protected

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

◆ $requestCookies

$requestCookies
protected

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

◆ $requestHeaders

$requestHeaders
protected

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

◆ $resource

$resource
protected

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

◆ $responseCookies

$responseCookies
protected

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

◆ $responseHeaders

$responseHeaders
protected

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

◆ $result

$result = ''
protected

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

◆ $socketTimeout

$socketTimeout = self::DEFAULT_SOCKET_TIMEOUT
protected

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

◆ $sslVerify

$sslVerify = true
protected

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

◆ $status

$status = 0
protected

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

◆ $streamTimeout

$streamTimeout = self::DEFAULT_STREAM_TIMEOUT
protected

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

◆ $version

$version = self::HTTP_1_0
protected

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

◆ $waitResponse

$waitResponse = true
protected

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

◆ BUF_POST_LEN

const BUF_POST_LEN = 131072

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

◆ BUF_READ_LEN

const BUF_READ_LEN = 16384

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

◆ DEFAULT_SOCKET_TIMEOUT

const DEFAULT_SOCKET_TIMEOUT = 30

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

◆ DEFAULT_STREAM_TIMEOUT

const DEFAULT_STREAM_TIMEOUT = 60

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

◆ DEFAULT_STREAM_TIMEOUT_NO_WAIT

const DEFAULT_STREAM_TIMEOUT_NO_WAIT = 1

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

◆ HTTP_1_0

const HTTP_1_0 = "1.0"

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

◆ HTTP_1_1

const HTTP_1_1 = "1.1"

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

◆ HTTP_DELETE

const HTTP_DELETE = "DELETE"

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

◆ HTTP_GET

const HTTP_GET = "GET"

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

◆ HTTP_HEAD

const HTTP_HEAD = "HEAD"

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

◆ HTTP_OPTIONS

const HTTP_OPTIONS = "OPTIONS"

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

◆ HTTP_PATCH

const HTTP_PATCH = "PATCH"

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

◆ HTTP_POST

const HTTP_POST = "POST"

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

◆ HTTP_PUT

const HTTP_PUT = "PUT"

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