2013-03-29 18 views
0

我在我的大學網絡上使用帶有身份驗證的代理服務器來瀏覽互聯網。如何在Ubuntu中設置php的代理?

我試圖用html_get_contents來從一個網站的數據,但在終端上運行的腳本給我這個錯誤:

PHP Warning: file_get_contents(http://www.google.com/): failed to open stream: Network is unreachable in /var/www/api/get_contents.php on line 2

我使用要做到這一點的代碼如下:

<?php 
    $contents = file_get_contents("http://www.google.com/"); 
    echo $contents; 
?> 

好像我需要設置代理的php獲得內容,我設置這個在哪裏?

回答

1

使用curl

http://www.php.net/manual/en/function.curl-setopt.php設置的選項:「CURLOPT_PROXYAUTH」,「CURLOPT_PROXYPORT」,「CURLOPT_PROXYTYPE」

+0

嘿,非常感謝@AlexeyKa,我想用'file_get_contents'現在,得到了從問題的答案在這裏:HTTP ://stackoverflow.com/questions/5139459/file-get-contents-behind-a-isa-proxy-under-apache RQ = 1 – jobin