• Модуль: pull
  • Путь к файлу: ~/bitrix/modules/pull/lib/jsonrpctransport.php
  • Класс: BitrixPullJsonRpcTransport
  • Вызов: JsonRpcTransport::performHttpRequest
static function performHttpRequest(string $body, array $options = []): MainResult
{
	$result = new MainResult();
	$httpClient = new MainWebHttpClient();

	$queueServerUrl = $options['serverUrl'] ?? Config::getJsonRpcUrl();
	$signature = CPullChannel::GetSignature($body);
	$hostId = (string)Config::getHostId();
	$urlWithSignature = CHTTP::urlAddParams($queueServerUrl, ["hostId" => $hostId, "signature" => $signature]);

	$sendResult = $httpClient->query(MainWebHttpClient::HTTP_POST, $urlWithSignature, $body);
	if (!$sendResult)
	{
		$errorCode = array_key_first($httpClient->getError());
		$errorMsg = $httpClient->getError()[$errorCode];
		return $result->addError(new MainError($errorMsg, $errorCode));
	}
	$responseCode = (int)$httpClient->getStatus();
	if ($responseCode !== 200)
	{
		return $result->addError(new MainError("Unexpected server response code {$responseCode}"));
	}
	$responseBody = $httpClient->getResult();
	if ($responseBody == '')
	{
		return $result->addError(new MainError('Empty server response'));
	}
	try
	{
		$decodedBody = MainWebJson::decode($responseBody);
	}
	catch (Throwable $e)
	{
		return $result->addError(new MainError('Could not decode server response. Raw response: ' . $responseBody));
	}

	return $result->setData($decodedBody);
}