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.