I want to send response to the client which should include some details in header which is common, let say userID and others datails in the body. How to add such new parameters to header of response,
I tried,
public function postAPIAction()
{
$jsonData = $this->getRequest()->getContent();
$decodePostRequest = json_decode($jsonData, true);
// processing is involved........
$uniqueKey=$this->generateUniqueKey();
$response = new Response();
$response->headers->add(array('userId' => $uniqueKey));
return new Response(json_encode(array('errorcode' => '1'), true));
}
which is not working.
You have to return the response you’ve set the headers on instead of creating a new one in the
returnstatement.