use strict; use warnings; use LWP::Simple; use WWW::Mechanize; use Compress::Zlib; # Create a new instance of WWW::Mechanize my $mechanize = WWW::Mechanize->new(autocheck => 1); $mechanize->cookie_jar(HTTP::Cookies->new); my $url = 'http://documents-dds-ny.un.org/doc/UNDOC/GEN/N08/588/39/pdf/N0858839.pdf?OpenElement'; my $file = 'test.pdf'; #getstore($url,$file); $mechanize->cookie_jar(HTTP::Cookies->new); $mechanize->get($url); my $response = $mechanize->response(); for my $key ( $response->header_field_names() ) { print $key, " : ", $response->header( $key ), "\n"; } my $dest = $mechanize->response->content; if($mechanize->response->header("Content-Encoding") eq "gzip") { $dest = Compress::Zlib::memGunzip($dest); $mechanize->update_html($dest); } $mechanize->get($url,":content_file" => $file); print $mechanize->content();