I found out a way to do it by using $http_response_header.
function SendRequest($url, $method, $data, $headers) {
$context = stream_context_create(array
(
'http' => array(
'method' => $method,
'header' => $headers,
//'content' => http_build_query($data)
'content' => $data
)
));
$response_body = file_get_contents($url, false, $context);
//var_dump($http_response_header);
return array(
'headers' => $http_response_header,
'body' => $response_body
);
}
*$http_response_header will be created in the local scope