如何获取请求页面的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人好少哦
自己动手,丰衣足食
呵呵,以为人家都和你一样是猫头鹰
你这是一觉醒来灵感来啊
呵呵,以为人家都和你一样是猫头鹰 - -
本文原创发布php中文网,转载请注明出处,感谢您的尊重!