On the basis of Bitrix I do API for the application. Is it possible to set the response headers from the server in the addressed file? In the bitrix documentation I found only:

use Bitrix\Main\Web\HttpClient; $httpClient = new HttpClient(); $httpClient->setHeader('Content-Type', 'application/json', true); 

But this is for requests from the server. Is there any method of installing response headers on a specific page or will you have to configure everything on the server?

    1 answer 1

    For example, in the template.php component you can call:

     <?if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die(); header('Cache-Control: no-cache, must-revalidate'); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); header('Content-type: application/json'); if($arResult["STATUS"] != "error") { $json = array( "total" => $arResult["TOTAL"], ); foreach($arResult["ITEMS"] as $arItem) { $arJson = array( "ID" => $arItem["ID"], ... ); $json["records"][] = $arJson; } } else { $json = array( "status" => "error", "message" => $arResult["MESSAGE"], ); } echo json_encode($json); 
    • header () - exactly, thanks! - Roman Avdeev