TA的每日心情 | 开心 2021-12-13 21:45 |
---|
签到天数: 15 天 [LV.4]偶尔看看III
|
通常我们调试WEB程序都是在 host配置文件绑定 xxx.com 192... ,然后重开浏览器,
curl 可以自动实现这块。
shell 代码
curl --silent -H "Host: www.zggo.com" "192.168.0.1/xxx/xxx/db.error.log"
php 代码
//httpHeader 设置的 http head 参数 数组形式 如 array("Host: client.51.com")
function comm_curl_request($url,$postString="",$httpHeader="")
{
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POSTFIELDS,$postString);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_USERAGENT,$_SERVER["HTTP_USER_AGENT"]);
if(!empty($httpHeader) && is_array($httpHeader))
{
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeader);
}
$data = curl_exec($ch);
$info = curl_getinfo($ch);
//var_dump($info);
curl_close($ch);
return $data;
}
|
|