如何获取请求页面的headers?
环境使用 nginx
是否是通过获取上一个页面的url 通过get_headers(url);来操作
还是有方便的函数可以直接获取headers的信息?
回复讨论(解决方案) curl 不是可以吗
// 请求数据$data ={\name\:\pdaloginout\,\value\:\1\};$url = http://localhost:801/testpostandget/testheader/getheader.php;$ch = curl_init($url);curl_setopt($ch,curlopt_customrequest,post);curl_setopt($ch,curlopt_postfields,$data);curl_setopt($ch,curlopt_returntransfer,true);curl_setopt($ch,curlopt_httpheader, array('content-type: application/json','username: 13540152637','token:321321321321321','content-length: ' . strlen($data)));$result = curl_exec($ch);
if ($_server ['request_method'] == 'post') { $body = @file_get_contents ( 'php://input' ); $json = urldecode ( $body ); $jsonpkg = json_decode ( $json, true ); $pkgkey = $jsonpkg ['reqname']; // 获取json中的参数 switch ($pkgkey) { case test : test ( $jsonpkg ); break; }} else { echo {“success”:“false”,“msg”:“参数错误”};}function test($jsonpkg) { $headers = array (); foreach ( $_server as $key => $value ) { if ('http_' == substr ( $key, 0, 5 )) { $headers [str_replace ( '_', '-', substr ( $key, 5 ) )] = $value; } } print_r($headers['username']); }
自己已解决 php人好少哦
自己动手,丰衣足食
呵呵,以为人家都和你一样是猫头鹰
你这是一觉醒来灵感来啊
呵呵,以为人家都和你一样是猫头鹰 - -