- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/lib/web/httpclient.php
- Класс: BitrixMainWebHttpClient
- Вызов: HttpClient::query
public function query($method, $url, $entityBody = null)
{
$this->effectiveUrl = $url;
$this->effectiveIp = null;
$this->error = [];
if (is_array($entityBody))
{
$entityBody = new HttpFormStream($entityBody);
}
if ($entityBody instanceof HttpStream)
{
$body = $entityBody;
}
elseif (is_resource($entityBody))
{
$body = new HttpStream($entityBody);
}
else
{
$body = new HttpStream('php://temp', 'r+');
$body->write($entityBody ?? '');
}
$this->redirectCount = 0;
while (true)
{
//Only absoluteURI is accepted
//Location response-header field must be absoluteURI either
$uri = new Uri($this->effectiveUrl);
// make a PSR-7 request
$request = new HttpRequest($method, $uri, $this->headers->getHeaders(), $body, $this->version);
try
{
// PSR-18 magic is here
$this->sendRequest($request);
}
catch (ClientExceptionInterface $e)
{
// compatibility mode
if ($e instanceof NetworkExceptionInterface)
{
$this->addError('NETWORK', $e->getMessage());
}
return false;
}
if (!$this->waitResponse)
{
return true;
}
if ($this->redirect && ($location = $this->getHeaders()->get('Location')) !== null && $location != '')
{
if ($this->redirectCount < $this->redirectMax)
{
// there can be different host in Location
$this->headers->delete('Host');
$this->effectiveUrl = $location;
$status = $this->getStatus();
if ($status == 302 || $status == 303)
{
$method = HttpMethod::GET;
}
$this->redirectCount++;
}
else
{
$this->addError('REDIRECT', "Maximum number of redirects ({$this->redirectMax}) has been reached at URL {$url}", true);
return false;
}
}
else
{
return true;
}
}
}