• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/exchange/integration/rest/client/base.php
  • Класс: BitrixSaleExchangeIntegrationRestClientBase
  • Вызов: Base::makeRequest
protected function makeRequest($method, $params = [])
{
	$accessToken = $this->getAccessToken();
	if ($accessToken === null)
	{
		throw new ObjectPropertyException("Access Token must be set.");
	}

	$endPoint = $this->getEndPoint();
	if ($endPoint === null)
	{
		throw new ObjectPropertyException("End Point URL must be set.");
	}

	$httpClient = new HttpClient();
	$httpClient->setHeader("User-Agent", "Bitrix Integration B24");
	$httpClient->setCharset("UTF-8");

	$params["auth"] = $accessToken;
	if (!Application::getInstance()->isUtfMode())
	{
		$params = Encoding::convertEncoding($params, SITE_CHARSET, "UTF-8");
	}

	$this->log("\----------n");
	$this->log(['endpoint'=>$endPoint.$method,'params'=>$params]);
	$this->log([$endPoint.$method.'?'.http_build_query($params)]);

	$success = $httpClient->post($endPoint.$method, $params);
	if (!$success)
	{
		throw new SystemException("Wrong Rest Response. ".$endPoint.$method);
	}

	$result = $httpClient->getResult();

	$this->log(['result'=>$result]);
	$this->log("n ----------//n");

	try
	{
		$response = Json::decode($result);
	}
	catch (Exception $exception)
	{
		throw new SystemException(
			"Wrong Rest Response. ".$endPoint.$method."nn".mb_substr($result, 0, 1024)
		);
	}

	return $response;
}