Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Connection through proxy 1

Status
Not open for further replies.

kokon

Programmer
Apr 27, 2006
31
0
0
PL
Hi, I`m using below code to connect to website. I want to connect to this site through the proxy server (I got servers with and some servers without authentification).
Please help.
Code:
use IO::Socket;
$Mhost="[URL unfurl="true"]www.google.com";[/URL]
$Msock = new IO::Socket::INET(PeerAddr => $Mhost, PeerPort => 80, Proto => 'tcp',Timeout=>60); 
$MURL="GET [URL unfurl="true"]http://www.google.com[/URL] HTTP/1.0\n\n";
print $Msock "$MURL"; 
while($line = <$Msock>) {$buf.=$line;}
print $buf;
 
This is how I've done it in the past:
Code:
#!/usr/bin/perl
use warnings;
use LWP::UserAgent;
$ua = LWP::UserAgent->new;
$ua->proxy(['http', 'ftp'] =>'http://[i]username[/i]:[i]password[/i]@FQDN.of.proxy:port');
$req = HTTP::Request->new('GET', "[URL unfurl="true"]http://www.my_page_here.com");[/URL]
$res = $ua->request($req);

Probably not the best way, but it works...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top