Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 无法分析响应头_Php_Python - Fatal编程技术网

Php 无法分析响应头

Php 无法分析响应头,php,python,Php,Python,我正在编写一个脚本,它发送一个GET请求,然后将响应中的Location头的值分配给一个变量,到目前为止,这是我的脚本 <?php $url = "http://www.example.com/"; $opts = array('http' => array( 'method' => 'GET', 'max_redirects' => '0', 'ignore_errors' => '1' ) );

我正在编写一个脚本,它发送一个GET请求,然后将响应中的
Location
头的值分配给一个变量,到目前为止,这是我的脚本

<?php

$url = "http://www.example.com/";

$opts = array('http' =>
    array(
        'method' => 'GET',
        'max_redirects' => '0',
        'ignore_errors' => '1'
    )
);

$context = stream_context_create($opts);
$stream = fopen($url, 'r', false, $context);

$headers = stream_get_meta_data($stream);


?>
我得到以下错误:

Notice: Undefined offset: 3 in /home/xxxxx/public_html/xxxx/file.php on line 24
以下是我想做的,但在python中:

import requests


url = "https://test.com/file.php?next=google"
headers = {"Cookie":"asd=123"}

req = requests.get(url,headers=headers,allow_redirects=False)

print "<img src=\""+req.headers['Location']+"\" >"
导入请求
url=”https://test.com/file.php?next=google"
头文件={“Cookie”:“asd=123”}
req=requests.get(url,headers=headers,allow\u redirects=False)
打印“”
通过使用

echo echo $headers["wrapper_data"][0];
而不是

echo $headers[0];
Do
var\u dump($headers)
查看变量实际包含的内容。
$headers[“wrapper_data”][0]不返回
位置
数据
echo $headers[0];