How to get/set Header in Rest Server API? How to get/set Header in Rest Server API? codeigniter codeigniter

How to get/set Header in Rest Server API?


May be try php function getallheaders() which will fetch all the header data for you. If you want to convert it into array, use foreach.

So this will get you the header data and will convert it into array

$headers=array();foreach (getallheaders() as $name => $value) {    $headers[$name] = $value;}

Now if you want to get body and convert it into array as well

$entityBody = file_get_contents('php://input', 'r');parse_str($entityBody , $post_data);

The final function will look something like this...

public function clientRequest_post() {    $headers=array();    foreach (getallheaders() as $name => $value) {        $headers[$name] = $value;    }    $entityBody = file_get_contents('php://input', 'r');    parse_str($entityBody , $post_data);    $this->response($entityBody, 200);}

Btw, I assume $this->response($entityBody,200); will generate the response for you. Best of luck with it