显示 PHP 为 HTTP 请求制作的确切标头


Show the exact header PHP made for HTTP requests?

有没有办法获取由file_get_contents()get_headers()等函数发送的确切标头?

喜欢

get_headers('http://google.it');
echo php_get_request_headers();  //> ?

曾经遇到过这个问题,所以我使用的是一个代理,例如fiddler http://www.fiddler2.com/fiddler2/

$default_opts = array(
  'http'=>array(
    'method'=>"HEAD",
    'proxy'=>"tcp://localhost:8888"
  )
);
$default = stream_context_set_default($default_opts);
$headers = get_headers('http://google.com');
var_dump($headers);

由于stream_context_set_default,它捕获此脚本发送的所有请求..这将适用于file_get_contentsfopen等。