我用下面的代碼的POST請求:PHP流 - 獲取所有HTTP請求頭
<?php
$url = 'http://www.example.com/';
$data = array('first-post-data' => 'data', 'second-post-data' => 'another-data');
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data),
'user_agent' => 'Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Firefox/24.0',
// corporate proxy thing ...
'proxy' => 'proxy-ip:proxy-port',
'request_fulluri' => true,
),
);
$context = stream_context_create($options);
$file = fopen($url, 'r', null, $context);
$content = stream_get_contents($file);
// Response headers:
echo '<pre>' . print_r(stream_get_meta_data($file), true) . '</pre>';
fclose($file);
echo $content;
我可以很容易地從功能stream_get_meta_data我手工製作的HTTP請求得到響應頭。是否有可能獲得所有請求標頭?有沒有內置功能?
編輯
我得到tcpflow原始的響應頭:https://superuser.com/a/23187 謝謝!
在你的情況下,沒有請求頭。上下文中的所有內容都在您的選項數組中。 – Spell
那麼,你將它們設置在'$ options'中 - 那麼有什麼問題呢? –
對不起,我的意思是,RAW請求標題...我想要捕獲整個請求流到達服務器的方式。 –