// 请求数据
$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人好少哦