时间:2021-07-01 10:21:17 帮助过:88人阅读
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']); }
自己动手,丰衣足食
呵呵,以为人家都和你一样是猫头鹰
你这是一觉醒来灵感来啊
呵呵,以为人家都和你一样是猫头鹰 - -