CodeIgniter Forums
Getting file contents over a proxy - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Getting file contents over a proxy (/showthread.php?tid=23723)



Getting file contents over a proxy - El Forum - 10-20-2009

[eluser]Boris Strahija[/eluser]
This is the situation. I have a list of proxy adresses, and they all require username and password. Now I need to get contents from a URL over those proxies. Choosing a proxy is not a problem, it will be done randomly, but nothing is working so far.
It's not really CI related, but it' actually part of a CI app Wink

Here's my code:
Code:
$authProx = base64_encode("my_username:my_password");

$header =     "Accept-language: en\r\n" .
            "Proxy-Authorization: Basic {$authProx}" ;

$ctx = stream_context_create(array(
    'http' => array(
         'timeout'         =>20
        ,'proxy'             =>'tcp://xx.xx.xx.xx:xxxx'
        ,'request_fulluri'     =>TRUE
        ,'header'         =>$header
        )
    )
);


$scrape_data = file_get_contents('http://www.my_url.hr', FALSE, $ctx);

And the error I keep getting:
Code:
A PHP Error was encountered

Severity: Warning

Message: file_get_contents(http://www.my_url.hr) [function.file-get-contents]: failed to open stream: HTTP request failed!

Filename: libraries/torrentfile.php

Line Number: 678

Any help would be appreciated.


Getting file contents over a proxy - El Forum - 10-20-2009

[eluser]pistolPete[/eluser]
Did you try cURL? http://www.higherpass.com/php/tutorials/Using-Curl-To-Query-Remote-Servers/3/


Getting file contents over a proxy - El Forum - 10-20-2009

[eluser]Boris Strahija[/eluser]
[quote author="pistolPete" date="1256088696"]Did you try cURL? http://www.higherpass.com/php/tutorials/Using-Curl-To-Query-Remote-Servers/3/[/quote]
Not yet, but I will try it out for sure tomorrow Wink