PHP发送请求头和接收打印请求头
程序员文章站
2022-03-26 16:17:58
...
PHP发送请求头和接收打印请求头
一、发送请求头
//发送地址 $url = 'http://127.0.0.1/2.php'; //请求头内容 $headers = array( 'Authorization: '.$basic, 'suibianzhi: '.$basic, ); //使用curl发送 $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $result = curl_exec($ch); curl_close($ch); echo $result;
二、接收并打印请求头
$headers = array(); foreach ($_SERVER as $key => $value) { if ('HTTP_' == substr($key, 0, 5)) { $headers[str_replace('_', '-', substr($key, 5))] = $value; } } echo ''; print_r($headers);
上一篇: HTTP请求头
下一篇: 如何安装mysql5.5?(图文详解)