原文地址为:
curl 请求指定host 的 URL
转载请注明本文地址: curl 请求指定host 的 URL
通常我们调试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; }
转载请注明本文地址: curl 请求指定host 的 URL