I am trying to download some excel files that are generated by pressing a link. At the press, the original site redirects the request to another site that generates the excel and the net result is a open/save/cancel/more_info prompt box. I need to save the file from the script. I could log-on to the website correctly by using LWP and am stuck there. The open/save prompt box is a seperate popup window, so I cannot view code behind it. I am a newby in this so do not know mechanism behind popups. Here is my code:
my $HOST = 'http://webserver_address'; my $DESTINATION = '/rel_path/nt/GetStats.asp' print "Enter Username: "; chop( $c0 = <STDIN> ); print "\n"; system "stty -echo"; print "Enter Password: "; chop( $c1 = <STDIN> ); print "\n"; system "stty echo"; package MyAgent; use base 'LWP::UserAgent'; sub get_basic_credentials { return "$c0", "$c1"; } package main; my $agent = MyAgent->new; push @{ $agent->requests_redirectable }, 'POST'; $agent->cookie_jar( HTTP::Cookies->new() ); my $response = $agent->get( "$HOST" ); print $response->code; #check after the initial login success if ( $response->is_success ) { print "\nGot OK\n"; print "Reading Excel...\n"; $response = $agent->request( POST $HOST . $DESTINATION, [ Prod => '8345', User => "$c0", Code => "ONET", URL => "http://anotherurl/getdata?action=li +ve_report&ID=3", ] ); if ( $response->is_success ) { $tmp = $response->content; } else { die "Request failed, got status [" . $response->status_line . "] +\n"; } }
Actual link that works from a browser:
http://webserver_address/rel_path/nt/GetStats.asp?Prod=8345&User=AVID& +Code=ONET&URL=http://another_url/getdata?action=live_report&ID=3
Runlog:
Enter Username: avid Enter Password: 200 Got OK Reading Excel... Request failed, got status [500 Internal Server Error]
I am also new to perl and gathered the above code by search-paste-play with the codes. Not knowing anything internal to lwp. :( Any help or insight will be greatly appreaciated.

In reply to LWP download: how to handle open/save/cancel prompt by avid

Title:
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, details, 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, summary, 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.