in reply to Re: Zip file from WWW::Mechanize
in thread Zip file from WWW::Mechanize

It works properly from a browser. Here are file listings of the same file: -rw-r--r-- 1 jack3 jack3 337991 2009-03-19 23:48 auto_20090318_0610.zip -rw-r--r-- 1 jack3 jack3 631747 2009-03-20 00:03 report.zip Jack

Replies are listed 'Best First'.
Re^3: Zip file from WWW::Mechanize
by ikegami (Patriarch) on Mar 23, 2009 at 18:17 UTC
    The newer file is twice the size. What's the output of
    od -c auto_20090318_0610.zip | head -n 4
    and
    od -c report.zip | head -n 4
      jack3:/usr/genoais/aiq/aiq/bin$ od -c auto_20090318_0610.zip | head -n + 4 0000000 P K 003 004 024 \0 \0 \0 \b \0 a I s : S +F 0000020 215 200 C & 005 \0 345 233 * \0 026 \0 \0 \0 a +u 0000040 t o _ 2 0 0 9 0 3 1 8 _ 0 6 1 +0 0000060 . c s v 344 275 [ s 333 310 226 . 370 > 021 36 +3 jack3:/usr/genoais/aiq/aiq/bin$ od -c report.zip | head -n 4 0000000 P K 003 004 024 \0 \0 \0 \b \0 a I s : S +F 0000020 357 277 275 357 277 275 C & 005 \0 357 277 275 357 277 27 +5 0000040 * \0 026 \0 \0 \0 a u t o _ 2 0 0 9 +0 0000060 3 1 8 _ 0 6 1 0 . c s v 357 277 275 35 +7
        "\215" (and basically every other byte ≥128) are being replaced with "\357\277\275". "\357\277\275" is the UTF-8 encoding of \x{FFFD}, the replacement character used to represent bad data.
        $ perl -MEncode -e'printf "%04X\n", ord decode "UTF-8", "\357\277\275" +' FFFD

        It sounds like something tried to decode the zip file.

        $ perl -MEncode -we'print decode "UTF-8", "\215"' | od -c Wide character in print at -e line 1. 0000000 357 277 275 0000003

        While WWW::Mechanize's content calls decoded_content (defined in HTTP::Message), decoded_content shouldn't attempt to decode a zip file (only files with MIME type text/*).

        Is the web server incorrectly saying the .zip is a UTF-8 text file? Could you provide the output of the following:

        print $mech->response()->headers()->as_string();

        Delete "Set-Cookie:" headers and other authentication data before posting.

Re^3: Zip file from WWW::Mechanize
by MidLifeXis (Monsignor) on Mar 23, 2009 at 17:36 UTC

    Please include some code; preferably the smallest amount possible that still reproduces your problem. Perhaps there is something inherently wrong with the code that extra eyes may see.

    --MidLifeXis

    The tomes, scrolls etc are dusty because they reside in a dusty old house, not because they're unused. --hangon in this post

      $mech = WWW::Mechanize->new(); $mech->quiet(0); $mech->agent_alias( 'Windows IE 6' ); $r = HTTP::Request->new( POST => "https://my.bandwidth.com" ); $r->content("/portal/"); $mech->request($r)->content; ... ... ... $matches[0] =~ /href.*?=.*?\"(.*?)\"/; print "Link: $1\n"; $getreport="https://my.bandwidth.com/portal/Members/Voice/$1"; $mech->get($getreport); $content=$mech->content; save_to_file($content, 'decode.zip', 1); sub save_to_file { my $xcontent = shift; my $filename = shift; open (LOG, ">$filename"); binmode LOG; print LOG $xcontent; close(LOG); }