如何配置cURL以使用PHP发送特定的HTTP头?

如何配置cURL以使用PHP发送特定的HTTP头?,curl,Curl,我正在尝试使用cURL和PHP向网站发送特定的HTTP头 当我用FireBug分析网络时,当我点击这个站点的链接时,我看到所有调用这个链接的POST和GET方法。这里是标题 响应标题: Connection Keep-Alive Content-Encoding gzip Content-Length 20 Content-Type text/html; charset=utf-8 Date Mon, 31 Dec 2012 12:55:57 GMT Keep-Alive

我正在尝试使用cURL和PHP向网站发送特定的HTTP头

当我用FireBug分析网络时,当我点击这个站点的链接时,我看到所有调用这个链接的POST和GET方法。这里是标题


响应标题:

Connection  Keep-Alive
Content-Encoding    gzip
Content-Length  20
Content-Type    text/html; charset=utf-8
Date    Mon, 31 Dec 2012 12:55:57 GMT
Keep-Alive  timeout=5, max=100
Location    http://www.example.com/a/b/11111
Server  Apache/2.2.22
Vary    Accept-Encoding
X-Powered-By    PHP/5.3.10-1ubuntu3.4
请求标头:

Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding gzip, deflate
Accept-Language es-ES,es;q=0.8,en-US;q=0.5,en;q=0.3
Connection  keep-alive
Cookie  referee_id=number;authautologin=number;session=number;uber_video=number
DNT 1
Host    www.example.com
Referer http://www.referersite.com
User-Agent  Mozilla/5.0 (Windows NT 6.1;WOW64;rv:17.0) Gecko/17.0 Firefox/17.0
已发送数据响应头

Content-Length  6
Content-Type    application/x-www-form-urlencoded

然后,在FireBug中,可以选择在新选项卡中再次发送所需的方法。它发送它,看起来就像我点击了链接,但实际上我没有点击,我使用了HTTP头。我想要做的是这样做,但使用卷曲。 这里你可以选择我说的:(Abrir en nueva pestaña=在新选项卡中打开)

下面是我的尝试:



我不能让它工作。有没有其他方法来使用HTTP头或者代码中有什么错误

<?
$url = 'http://www.example.com/a/b/1?c=1'; 

function disguise_curl($url) { 
  $curl = curl_init(); 

  $header[] = "Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; 
  $header[] = "Cache-Control: max-age=0"; 
  $header[] = "Connection: keep-alive"; 
  $header[] = "Keep-Alive:timeout=5, max=100"; 
  $header[] = "Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3"; 
  $header[] = "Accept-Language:es-ES,es;q=0.8"; 
  $header[] = "Pragma: "; 

  curl_setopt($curl, CURLOPT_URL, $url); 
  curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11'); 
  curl_setopt($curl, CURLOPT_HTTPHEADER, $header); 
  curl_setopt($curl, CURLOPT_REFERER, 'http://www.referersite.com'); 
  curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate,sdch'); 
  curl_setopt($curl, CURLOPT_AUTOREFERER, true); 
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
  curl_setopt($curl, CURLOPT_TIMEOUT, 10); 

  $html = curl_exec($curl); 
  curl_close($curl);
} 
echo disguise_curl($url); 
?>