Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
#!/usr/bin/perl -- use strict; use warnings; use LWP; use File::Slurp qw' read_file write_file '; use File::Spec; Main(@ARGV); exit(0); sub Main { my $mech = LWP::UserAgent->new; my $ua = $mech; $ua->add_handler( "request_send", sub { shift->dump; return } ); $ua->add_handler( "response_done", sub { shift->dump; return } ); my $file = File::Spec->rel2abs(__FILE__) . '.temp.html'; #~ print "$file \n"; write_file( $file, ( '#' x ( 5810-9 ) ) ); $ua->resume( '', $file ); print "----\n",substr( read_file( $file ), -20 ), "\n\n"; unlink $file; } ## end sub Main sub LWP::UserAgent::resume { my ( $self, $uri, $file, @rest ) = @_; ## TODO: Accept-Ranges ## TODO: If-Range ## TODO: If-Unmodified-Since ## TODO: Last- Modified eval { $uri = $uri->url if ref($uri) eq 'WWW::Mechanize::Link'; $uri = $self->base ? URI->new_abs( $uri, $self->base ) : URI-> +new($uri); }; open my ($fh), '>>', $file or die "Can't open '$file' for append: +$!"; binmode $fh; @rest = ( ':content_cb' => sub { my ( $data, $response, $protocol ) = @_; print $fh $data; return; }, @rest ); my @stat = stat($fh); ## 9 mtime require HTTP::Request::Common; my @suff = $self->_process_colonic_headers( \@rest, 0 ); my $req = HTTP::Request::Common::GET( $uri, @rest ); $req->headers->header( Range => 'bytes=' . $stat[7] . '-' ); @rest = $self->request( $req, @suff, @rest ); close $fh; return @rest; } ## end sub LWP::UserAgent::resume __END__ GET Range: bytes=5804- User-Agent: libwww-perl/5.837 (no content) HTTP/1.1 206 Partial Content Connection: close Date: Sat, 02 Oct 2010 01:39:24 GMT Accept-Ranges: bytes ETag: "61c606-16b2-491805f445dc0" Server: Apache/2.2.14 (Unix) Content-Length: 6 Content-Range: bytes 5804-5809/5810 Content-Type: text/html; charset=ISO-8859-1 Last-Modified: Thu, 30 Sep 2010 21:00:47 GMT Client-Date: Sat, 02 Oct 2010 01:40:23 GMT Client-Peer: Client-Response-Num: 1 (no content) ---- ########### </html>

In reply to Re^2: file download with connection problems by Anonymous Monk
in thread file download with connection problems by balushen

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others romping around the Monastery: (5)
    As of 2020-10-21 05:12 GMT
    Find Nodes?
      Voting Booth?
      My favourite web site is:

      Results (212 votes). Check out past polls.