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";
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|