Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??


I attempt to download large files (~20MB+ zip, pdf) from a website (collabnet teamforge) which is using https protocol. I wrote a perl script using WWW::Mechanize and tried to save the file using 'save_content' function like below.

#initialise browser object $browser = WWW::Mechanize->new(autocheck =>1, noproxy =>1); # Add cookie jar $browser->cookie_jar(HTTP::Cookies->new()); $browser->agent_alias('Linux Mozilla'); .... $browser->get($collabnetArtifactURL); #Serach and follow the file / doc link in collabnet $tmpURL = $browser->find_link(tag=>'a',url_regex => qr/\/sf\/(docm +an|frs)\/do\/(downloadDocument|downloadFile)\/.*\/$artID/)->url_abs() +; $tmpURL.='/'.$collabnetFileVersion if ($collabnetFileVersion ne '' +); print "\n INFO: URL: $tmpURL"; #print "\n ", Dumper($response) , "\n"; $response = $browser->get($tmpURL); if ($browser->success()) { if ($collabnetFileName eq '') { $collabnetFileName = $response->filename() || $artID; } $browser->save_content($collabnetFileName); if (-s $collabnetFileName) { print "\n INFO: $collabnetFileName is downloaded"; } else { print "\n ERROR: $collabnetFileName is NOT downloaded"; } } ....

This is just a code snip set only not running code.

This code works find in Linux machine with perl 5.8.8 but failes to download files properly in Windows OS. I tried to decode_content and realise that only first chunk of data came and immediately client (perl script) sends x-die header. That means, In windows Active perl 5.12.x , downloading large binary files via https is not working.

The underlying problem was , perl lwp can not deflate the gzip data because , lwp dies before getting all the chunk of the big file. I searched a lot in google but did not find right solution. Because this appears to be Windows only problem.

Finally i made it working with using Crypt::SSLeay . By default in windows OS, LWP uses IO::Socket::SSL to handle https. which is not working for me. So i had to force LWP to use Net::SSL (provided by Crypt::SSLeay) using following code

use strict; use warnings; use Crypt::SSLeay; use Net::SSL; use WWW::Mechanize; use HTTP::Cookies; .... $ENV{PERL_NET_HTTPS_SSL_SOCKET_CLASS} = "Net::SSL"; $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0; ... # Same above code

That is it. Everything works fine after I added above code.

Perl technology demo project -

In reply to Downloading large Binary files from https protocol using WWW::Mechanize in Windows OS by sam_bakki

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 all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others about the Monastery: (5)
    As of 2018-07-17 04:17 GMT
    Find Nodes?
      Voting Booth?
      It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

      Results (354 votes). Check out past polls.