I'm using fopen('http://server/path')
and I'd like to get body of http request that php is sending to remote server (for checking & logging).
I've found and read this discussion: PHP file_get_contents() and setting request headers
I know how to set headers I need.
I'm looking for a way to get full http request body that php is sending or just sent to remote server.
$url = 'http://server/path'
$content = json_encode(array(
'a' => 1
, 'b' => 2
));
$options = array(
'http' => array(
'header' => array(
'Content-Type: application/json'
, 'Content-Length: ' . strlen($content)
)
, 'method' => 'POST'
, 'content' => $content
)
);
$context = stream_context_create($options);
$f = fopen($url, 'r', false, $context);
// >>> Here I'd like to get full request that php is just sent to remote server <<<
fclose($f);
For the code provided, I'd like to be able to get this:
POST /path HTTP/1.0
Host: server
Content-Type: application/json
Content-Length: 13
{"a"=1,"b"=2}
Is it possible to do while using fopen
?
Thanks.