2016-09-27 23 views
0

我覺得沒有辦法PHP捲曲這個網址:PHP捲曲沒有辦法在這個特定的URL

http://www.bvger.ch/publiws/pub/cache.jsf?displayName=A-1695/2006&decisionDate=2007-02-27

任何你能幫助我嗎?我嘗試了很多方法但沒有取得任例如:

FUNCTION get_data2($url) 
{ 
    $curl = curl_init(); 
    $header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,"; 
    $header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"; 
    $header[] = "Cache-Control: max-age=0"; 
    $header[] = "Connection: keep-alive"; 
    $header[] = "Keep-Alive: 300"; 
    $header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7"; 
    $header[] = "Accept-Language: en-us,en;q=0.5"; 
    $header[] = "Pragma: "; // browsers keep this blank. 
    curl_setopt($curl, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
    curl_setopt($curl, CURLOPT_USERAGENT, 'Googlebot/2.1 (+http://www.google.com/bot.html)'); 
    curl_setopt($curl, CURLOPT_HTTPHEADER, $header); 
    curl_setopt($curl, CURLOPT_REFERER, 'http://www.google.com/bot.html'); 
    curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate'); 
    curl_setopt($curl, CURLOPT_AUTOREFERER, true); 
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($curl, CURLOPT_TIMEOUT, 10); 
    $html = curl_exec($curl); // execute the curl command 
    curl_close($curl); // close the connection 
    return $html; // and finally, return $html 
} 

OR

FUNCTION get_data1($url) 
{ 
$ch = curl_init(); 
$timeout = 5; 
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1"); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); 
$data = curl_exec($ch); 
curl_close($ch); 
return $data; 
} 

兩個返回任何迴應。

回答

1

這個工作對我很好......

function get_data2($url) 
{ 
    $curl = curl_init(); 
    $header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,"; 
    $header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"; 
    $header[] = "Cache-Control: max-age=0"; 
    $header[] = "Connection: keep-alive"; 
    $header[] = "Keep-Alive: 300"; 
    $header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7"; 
    $header[] = "Accept-Language: en-us,en;q=0.5"; 
    $header[] = "Pragma: "; // browsers keep this blank. 
    curl_setopt($curl, CURLOPT_URL, $url); 
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); 
    curl_setopt($curl, CURLOPT_USERAGENT, 'Googlebot/2.1 (+http://www.google.com/bot.html)'); 
    curl_setopt($curl, CURLOPT_HTTPHEADER, $header); 
    curl_setopt($curl, CURLOPT_REFERER, 'http://www.google.com/bot.html'); 
    curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate'); 
    curl_setopt($curl, CURLOPT_AUTOREFERER, true); 
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($curl, CURLOPT_TIMEOUT, 10); 
    $html = curl_exec($curl); // execute the curl command 
    curl_close($curl); // close the connection 
    return $html; // and finally, return $html 
} 

$url = 'http://www.bvger.ch/publiws/pub/cache.jsf?displayName=A-1695/2006&decisionDate=2007-02-27'; 

echo get_data2($url); 

不要利用 「功能」。此外,您必須剪切粘貼,並且不使用$ curl而不是$ ch修正其中一行以匹配其他行。

+0

謝謝你幫助初學者。 – Amateur