0

我正在尝试使用 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 标头。我想要的是这样做,但使用 cURL。在这里你有我说的选项:http ://img5.imageshack.us/img5/3841/sinttulodho.png (Abrir en nuevapestaña = Open in new tab)

所以这是我的尝试:


<?
$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); 
?>

我不让它工作。任何其他使用 HTTP 标头的方法或代码中的错误?

4

0 回答 0