标签:http os io 使用 ar 文件 div cti sp
From : http://digdeeply.org/archives/10132139.html
我们在开发测试时,有时web服务器会绑定一个域名,但是因为dns是无法解析的,我们需要设置host文件去访问。
但是,如果我们是需要通过curl访问的话,无法访问该url的host主机。所以,需要通过指定host的方式来访问,具体访问方式如下:
如果是linux下的curl命令:
|
1
|
curl --silent -H "Host: www.digdeeply.info" "192.168.0.1/index.php" |
如果使用php的curl的话,使用curl_setopt设置一下CURLOPT_HTTPHEADER即可。
请参考以下函数使用:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
//httpHeader 设置的 http head 参数 数组形式 如 array(‘Host: digdeeply.info‘)function curl_by_host($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); curl_close($ch); if(curl_errno($ch)){ return $info; } return $data;} |
[转]php curl 设置host curl_setopt CURLOPT_HTTPHEADER 指定host
标签:http os io 使用 ar 文件 div cti sp
原文地址:http://www.cnblogs.com/Athrun/p/3951228.html