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.


In reply to Re^3: Problems with IO::Socket::INET by scottknight
in thread Problems with IO::Socket::INET by scottknight

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.