http://qs1969.pair.com?node_id=470674

jaydon has asked for the wisdom of the Perl Monks concerning the following question:

I need to access a site where the login page uses an https URL and then get data off an http URL.
I'm approaching this problem by first doing a GET HTTP::Request of the login page and then a POST HTTP::Request to the login page and providing the username and password.

I then plan to do another GET to the data url.


My problem is in the POST.

When I look at the returned page, it is the same as what gets returned for the initial GET, where the user is getting prompted for the login info.


I'm new to perl and would really appreciate any advice.

Here is my code:

use LWP::UserAgent; use HTTP::Cookies; use LWP::Simple; use HTTP::Request; use strict; my $ua = LWP::UserAgent->new; $ua->agent("Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)"); my $cj = HTTP::Cookies->new(file => "lwp.cookie", autosave => 1); $ua->cookie_jar($cj); $cj->save; my $req1 = HTTP::Request->new(GET => 'https://www.samplesite.com/myacc +ount/default.asp?sp=login'); my $res1 = $ua->request($req1); if ($res1->is_success) { print "1st step complete\n"; } else { print "Error: " . $res1->status_line . "\n"; } my $req2 = HTTP::Request->new(POST => 'https://www.samplesite.com/myac +count/default.asp?sp= login', [username => "samp2", password => "data362"],); if ($res2->is_success) { print $res2->content; print "Step 2 ocmplete\n"; } else { print "Error: " . $res2->status_line . "\n"; }