Hello, I am trying to write a script that gets the content of a web page for a platform that has a pretty stripped Perl 5.8.0. LWP and CPAN are not included and I was hoping to not require or need to distribute LWP to do what I want, so I wrote this instead:
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'; } $sock->print("GET /".$filename." HTTP/1.0\r\n"); $sock->print("Host: $host\r\n"); $sock->print("Authorization: Basic $pass64\r\n"); $sock->print("\r\n"); while (<$sock>) { printf $_; } close($sock);
This has been working just fine until I came up against a D-Link modem that only spits back 501 Not Implemented messages at it. I found that it also kind of works on a Linksys wireless access point since it will happily get the root url, but a request for any other doc will return a 403 Error.

When using wget 1.6 or 1.9, I am always able to get all of the docs from all of the devices I try, so at least I have a benchmark.

I used ethereal to sniff the packets to see if I could find any difference between the wget and my script's traffic. There were only two differences:

    1) With wget, the Authorization: Basic string has the \r\n at the end, where the one I send with Perl only has \n. This should not be a problem with the D-Link since it doesn't require authentication. It's still an unexpected anomoly.

    2) With wget, the entire request shows up as a single packet in ethereal (GET, Host, User-Agent, Content-Type, etc). With Perl it shows a single packet that ends at the end of the GET line and a 'Continuation' packet that contains the rest of the request. The end of the packet that contains the GET, is just \r\n, so I cannot figure out why it is broken into two packets.

Anyone have any hints at all? (besides "Just use LWP")

Thanks.

In reply to 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.