I've done some work with HTTP requests, and I've had more success with IO::Socket::INET. This is a sub I use for various web client applications. It's consistently quick on UNIX and Windows.

I ran this script on both Linux and Windows using perl 5.8.8, and in both cases it took 2 seconds to download 14M. (time does not include writing it to a file)

package HTTP::Request; use IO::Socket::INET; use warnings; use strict; use Carp; our $VERSION = '1.000'; my ($content, $tags) = get_url( { webserver => 'www.example.com', url => '/', port => 80, verbose => 0, #Print the HTTP message sequence download => 1, #Mostly for crawler applications. Content type +s without #links are not retrieved if set to 0. }); if ($content) { print "Elapsed time: $tags->{elapsed}\n"; print "Downloaded page:\n$content\n"; } else { print "Content is not available\n"; } sub get_url { my ($parameter) = @_; my $submit; my $port = 80; my $content = ''; my %tag; my $t1 = time; if (!exists ($parameter->{webserver}) or !exists ($parameter->{url})) { croak "Missing webserver or URL information"; } if (defined ($parameter->{port})) { $port = $parameter->{port}; } my $webserver = $parameter->{webserver}; my $url = $parameter->{url}; my $sock = IO::Socket::INET->new( PeerAddr => $webserver, PeerPort => $port, Proto => 'tcp', Timeout => 10 ); my $line; my $new_location; my @output = (); my @headers = (); my $header; if ($sock) { $sock->autoflush(); $submit = <<"END_GET"; GET $url HTTP/1.0 Host: $webserver User-Agent: HTTPR/1.1 END_GET print $sock $submit; while ( $line = <$sock> ) { #separate loop to save processin +g on body $line =~ s/\s+$//; if ( $line =~ /^\s*$/ ) { last; } push @headers, $line; if ($line =~ /^Location: (.+)/) { $new_location = $1; } } $tag{proto} = $headers[0]; $tag{elapsed} = time - $t1; $tag{url} = $url; foreach my $stat (@headers[1 .. $#headers]) { $stat =~ /^(.+): (.*)$/; $tag{lc $1} = exists($tag{lc $1}) ? $tag{lc $1} . ', ' . + $2 : $2; } $headers[0] =~ /HTTP\/\d+\.\d+ (\d+)/m; my $http_status = $1; if ($http_status == 200 and ($tag{'content-type'} =~ /text|css|html/ or $parameter-> +{download})) { if (exists($tag{'content-length'})) { #optimized reading if available $sock->read($output[0], $tag{'content-length'}); } else { local $/; while ( $line = <$sock> ) { $line =~ s/\s+$//; push @output, $line; } } } if ($parameter->{verbose}) { print $submit . "\n"; print join ("\n", @headers) . "\n"; print "\n\n" . join ("\n ", @output); print "\n=============================================== +===\n"; } if ($http_status == 301) { print "Page is relocated to $new_location\n"; return; } elsif ($http_status != 200){ print "ERROR webserver could not process request!\n" . join ("\n ", @headers) . "\n"; return; } else { $content = join ('', @output); } } else { print "Could not connect to $webserver port 80.\n"; return; } return ($content, \%tag); }

In reply to Re: LWP slow downloads on windows by tprocter
in thread LWP slow downloads on windows by robobunny

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.