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 -