dave_the_m,
Thank you very much for your help. I suspected it was something with the fact that I was using print, but not that it was multiple print statements since the 'rest' of the request was contained in one packet (or so it seems, looking at ethereal output). At any rate, if I construct a single string and send that as a single print, it behaves the same way through ethereal. Now, I am getting a different error from the Linksys, but I suspect that is a different issue.
As for the carriage returns, I was only using \r\n because that is what the examples I worked from used and the ethereal output from wget confirmed. I am working on Linux and have no current plans to port this to any other platforms, but you have piqued my interest. When I use \015\012 in place of the \r\n in my string, I get exactly the same results when looking at the packet....even the mysterious missing \r after the base64 encoded string.
Off for more testing. Thanks again for your help. | [reply] |
I just thought I would post a final follow-up to this thread. Thanks to the advice of dave_the_m, I have this working splendidly and figure a snippet of code might help someone who wants a lightweight and simpla alternative to LWP for whatever reason (mine is that Smoothwall doesn't have it and I don't want to distribute it). Here is code that will work ($host, $port, $filename, $username, $password are all just plain strings passed in from somewhere else):
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. | [reply] [d/l] |