Php 无法分析响应头
我正在编写一个脚本,它发送一个GET请求,然后将响应中的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' ) );
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];
Dovar\u dump($headers)
查看变量实际包含的内容。$headers[“wrapper_data”][0]代码>不返回位置
数据
echo $headers[0];