2012-12-01 32 views
2

我的問題代碼CURLOPT_NOBODY影響響應頭當我使用捲曲

<?php 
$curl = curl_init(); 
curl_setopt($curl, CURLOPT_URL, 'http://www.tudou.com/programs/view/qyT7G6gVFSs'); 
curl_setopt($curl, CURLOPT_HEADER, 1); 
curl_setopt($curl , CURLOPT_NOBODY, true); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
$data = curl_exec($curl); 
curl_close($curl); 
var_dump($data); 

響應是

串(241),「HTTP/1.1 405不允許的方法 服務器:Tengine/1.4.0 日期:星期六,2012年12月1日15時53分32秒GMT 的Content-Type:text/html的;字符集= GBK 的Content-Length:1085 連接:關閉 APPSRV:ItemView控件-APP4-app_admin 有所不同:接受編碼 允許:GET 「

然後我正確的代碼是

<?php 
$curl = curl_init(); 
curl_setopt($curl, CURLOPT_URL, 'http://www.tudou.com/programs/view/qyT7G6gVFSs'); 
curl_setopt($curl, CURLOPT_HEADER, 1); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
$data = curl_exec($curl); 
curl_close($curl); 
var_dump($data); 

結果是 串(313)」 HTTP/1.1 302已暫時移動 服務器:Tengine/1.4.0 日期:星期六, 2012年12月1日十六時17分25秒GMT 的Content-Length:0 連接:關閉 APPSRV:ItemView控件-APP5-app_admin 有所不同:接受編碼 雜注:無緩存 緩存控制:無緩存,NO-商店 Expir ES:週四,01 1 1970 00:00:00 GMT 地點:http://tv.tudou.com/

是的,它只是CURLOPT_NOBODY,任何人都可以告訴我爲什麼請!

回答

0

嘗試做這樣的事情:

  //cURL set options 
      //cURL options array set 
      $options = array(
       CURLOPT_URL => $this->URL,    #set URL address 
       CURLOPT_USERAGENT => $this->UserAgent, #set UserAgent to get right content like a browser 
       CURLOPT_RETURNTRANSFER => true,   #redirection result from output to string as curl_exec() result 
       CURLOPT_COOKIEFILE => 'cookies.txt', #set cookie to skip site ads 
       CURLOPT_COOKIEJAR => 'cookiesjar.txt', #set cookie to skip site ads 
       CURLOPT_FOLLOWLOCATION => true,   #follow by header location 
       CURLOPT_HEADER => true,     #get header (not head) of site 
       CURLOPT_FORBID_REUSE => true,   #close connection, connection is not pooled to reuse 
       CURLOPT_FRESH_CONNECT => true,   #force the use of a new connection instead of a cached one 
       CURLOPT_SSL_VERIFYPEER => false   #can get protected content SSL 
      ); 
      //set array options to object $curl 
      curl_setopt_array($curl, $options);