客户端在请求时在http
请求的header
中加入了一些自定义参数,
但是以net_
,os_
,device_
开头的一些参数在后端无法获取到。
后端使用的 php,打印$_SERVER
没有这些参数
看了http协议
和cgi协议
也没有找到相关说明
不太明白怎么回事
客户端在请求时在http
请求的header
中加入了一些自定义参数,
但是以net_
,os_
,device_
开头的一些参数在后端无法获取到。
后端使用的 php,打印$_SERVER
没有这些参数
看了http协议
和cgi协议
也没有找到相关说明
不太明白怎么回事
谢邀!
<?php
header('Access-Control-Allow-Origin:*');
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Allow-Methods:GET,PUT,POST,DELETE,OPTIONS');
header('Access-Control-Allow-Headers:WWW-Authenticate,Authorization,Set-Cookie,X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version');
// 获取头部信息end
$header = apache_request_headers();
// 取head标签内容
var_Dump($header);exit;
?>
获取的时候前面要HTTP_
:
$_SERVER['HTTP_Authorization']
找到原因了
不只是net_
,os_
,device_
开头的一些参数,默认情况下nginx会自动drop所有带下划线的header
需要设置 underscores_in_headers on;
If you do not explicitly set underscores_in_headers on;
, nginx will silently drop HTTP headers with underscores (which are perfectly valid according to the HTTP standard). This is done in order to prevent ambiguities when mapping headers to CGI variables, as both dashes and underscores are mapped to underscores during that process.
15 回答8.4k 阅读
1 回答4k 阅读✓ 已解决
3 回答1.8k 阅读✓ 已解决
2 回答2.2k 阅读✓ 已解决
2 回答2.4k 阅读✓ 已解决
1 回答1.8k 阅读✓ 已解决
1 回答1.4k 阅读✓ 已解决
你试一下apache_request_headers() 函数 获取一下看能够获取到吗?