2015-02-23 45 views
0

我試圖從curl和php頁面獲取html。我有以下的代碼,它完美的作品在我的主機:在不同的主機上沒有收到傳輸

<?php 

$curl = curl_init(); 

$URLs[] = "http://www.stackoverflow.com"; 

echo request($curl, $URLs[0]); 

function request($curl, $url, $post = null) 
{ 
    echo (isset($post) ? 'POST ' . $url : 'GET ' . $url) . PHP_EOL; 
    try 
    { 
     curl_setopt_array($curl, array 
     (
      CURLOPT_RETURNTRANSFER => true, 
      CURLOPT_FOLLOWLOCATION  => true, 
      CURLOPT_HEADER     => true, 
      CURLOPT_AUTOREFERER   => true, 
      CURLOPT_SSL_VERIFYPEER  => false, 
      CURLOPT_URL     => $url, 
      CURLOPT_USERAGENT  => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:30.0) Gecko/20100101 Firefox/30.0', 
      CURLOPT_HTTPHEADER  => array 
      (
       'Accept-Language: en-US;q=0.6,en;q=0.4', 
       'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' 
      ) 
      )); 
      return curl_exec($curl); 
     } 
    catch(Exception $exception) 
    { 
     echo $exception; 
    } 
}   
curl_close($curl); 
?> 

當我把它放在我的虛擬主機提供商,我沒有得到任何迴應。我檢查了curl錯誤,並且顯示「無法設置網址!」。請提供任何提示?謝謝!

+0

啓用您的虛擬主機提供商上延伸捲曲? – mpalencia 2015-02-23 09:27:03

+0

我相信是這樣,它在php_info中列出,我相信curl不會給出'無Url Set'錯誤。 – Kristian 2015-02-23 12:01:09

回答

0

嘗試的捲曲處理這個其他格式,在curl_init函數初始化主持人:

$url = .... 
    $arrayConfig = .... 

    $curl = curl_init($url); 
    curl_setopt_array($curl,$arrayConfig); 
    $content = curl_exec($curl); 
    $err  = curl_errno($curl); 
    $errmsg = curl_error($curl) ; 
    $header = curl_getinfo($curl); 
    curl_close($curl); 
相關問題