in reply to Re^2: Problems with IO::Socket::INET
in thread Problems with IO::Socket::INET
use IO::Socket::INET; use MIME::Base64 (); $pass64 = MIME::Base64::encode_base64("$username:$password", ""); my $sock; unless ($sock = new IO::Socket::INET (PeerAddr => $host, PeerPort => $ +port, Proto => 'tcp', Timeout => 5)) { $errormessage = $tr{'could not connect to http://$host:$port/$file +name'}; return '0'; } my $request = ""; my $eol = "\015\012"; $request = $request."GET /$filename HTTP/1.0".$eol; $request = $request."User-Agent: Perl/5.8.0".$eol; $request = $request."Host: $host:$port".$eol; $request = $request."Accept: */*".$eol; $request = $request."Connection: Keep-Alive".$eol; if ($auth_required) { $request = $request."Authorization: Basic $pass64".$eol; } $request = $request."$eol"; $sock->print($request); while (<$sock>) { printf $_; } close($sock);
Obviously, in that while loop, you will want to do something more useful with the data than print it to the console :) I put each line into an array element.
|
|---|