PHP api调用头变量检索


PHP api call header variable retrieval

我正在使用一个api,它在头响应中返回许多有用的变量,例如…

Pragma → no-cache
Server → Apache
X-Pages → 1424

…我想使用X-Pages变量来形成一些进一步的逻辑。我如何检索这个变量并在我的php脚本中使用它?

我的api当前调用是这样的:

$username = "XXXXXXXX";
$password = "XXXXXXXX";
$remote_url = 'XXXXXXXX';
$headers = array();
$headers[] = "Authorization: Basic " . base64_encode("$username:$password");
$opts = array(
  'http'=>array(
    'method'=>"GET",
'header' => $headers
  )
);
$context = stream_context_create($opts);
$file1 = file_get_contents($remote_url, false, $context);

谢谢,马特

您可以在呼叫file_get_contents后在$http_response_header中找到响应头-它将自动填充到本地范围