HttpClient constructor
public \Bitrix\Main\Web\HttpClient::__construct( array $options = null );
Non-static method is called when creating a class instance, allowing to perform specific actions within it when creating an object.
Parameters
Parameter | Description | Version |
---|---|---|
options | Array with parameters:
All these options are optional when creating a class instance, they can be configured later. |
Example
Create a class instance:
$http=new \Bitrix\Main\Web\HttpClient(array $options = null);)
Execute GET query. Parameter requires absolute pathname. Returns a response string or false, when error occurs. Please, be advised, that empty string is not an error.
$http->get($url)
Execute POST query. First parameter contains absolute pathname. Second parameter must be an array, string, object. Similar to the previous method, returns a response string or false, when error occurs.
$http->post($url, $postData = null)
Specify http header in the query. First parameter sets header field name, second parameter indicates this field value. (Be advised, that in both cases, string is passed. When several headers are needed, the method must be called several times.) Third parameter is responsible for header rewriting when parameter with the same name already is specified.
$http->setHeader($name, $value, $replace = true)
Specifying cookies for query. The only parameter receives array with key as the cookies name and value is the cookies value.
$http->setCookies(array $cookies)
Specifying header field for basic http authorization query. User name and password are passed in parameters.
$http->setAuthorization($user, $pass)
Specifying forwarding options. First parameter enables forwarding and second parameter sets maximum number of redirects.
$http->setRedirect($value, $max = null)
Specifying parameter, that sets server's response timeout or connection closure immediately after query. Standby by default.
$http->waitResponse($value)
Specifying maximum response timeout in seconds.
$http->setTimeout($value)
Specifying HTTP protocol version. Default version is 1.0. Can be specified as 1.1
$http->setVersion($value)
Enables use of compression. Please note, the compressed response is processed in any case when headers are passed correctly.
$http->setCompress($value)
Specifying encoding for bodies of objects for POST and PUT queries.
$http->setCharset($value)
Specifying parameter for use proxy server. Specifies host or an address as the first parameter. Second parameter specifies port and third parameter - user name. Fourth parameter contain password. All parameters except host name are optional.
$http->setProxy($proxyHost, $proxyPort = null, $proxyUser = null, $proxyPassword = null)
Specifying the result as stream. Parameter passes a resource to file or to stream.
$http->setOutputStream($handler)
Downloading and saving the file. First parameter is the address used to download the file. Second parameter is the absolute pathname for saving the file.
$http->download($url, $filePath)