Plankton has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/local/bin/perl -w use strict; use LWP::UserAgent; use LWP::Simple; use HTTP::Cookies; use HTTP::Request::Common; use HTTP::Headers; . . . sub do_LWPsetup { my $ref2browser = shift; $HTTP::Request::Common::DYNAMIC_FILE_UPLOAD = 1; #create an LWP browser object $$ref2browser = LWP::UserAgent->new(); #allow POST redirects push @{$$ref2browser->requests_redirectable}, 'POST'; #enable cookie support (dont know if this is really neccesary $$ref2browser->cookie_jar(new HTTP::Cookies ); return 1; } sub do_logon { my $userid = shift; my $password = shift; my $url = shift; my $browser = shift; my $loginurl = "$url/logon.jsp"; my $resp = $browser->post($loginurl, [ 'j_username' => $userid, 'j_password' => $password, 'submit' => 'Submit' ]); print "do_logon " . __FILE__ . "[" . __LINE__ ."] resp =[" . Dumpe +r($resp) . "]\n"; if (do_errorcheck($resp,'Logon')) { print $resp->{'_msg'} . "\n"; +return 0; } if ($debug_level > 0) { print "\nLogon Success: $userid"; } return 1; } . . . getUserPassword( \$user, \$password ); my $browser; my $rc = do_LWPsetup( \$browser ); if ($rc==0) { print "Failure: do_LWPStuff failed\n"; exit 1; } if (!do_logon( $user, $password, $url, $browser )) { print "Failure: do_logon failed\n"; exit 2; } else { print "Where in!\n"; }
Enter user: TEST001 Enter password: ******* do_logon BEGIN myscript.pl[269] do_logon resp myscript.pl[283] resp =[$VAR1 = bless( { '_protocol' => 'HTTP/1.1', '_content' => ' <html> <head> <title> xyz Secure HTTP File Uploader Logon </title> </head> <center> <br><br><form action="j_security_check" method=post> <table> <tr> <td align="center" > <table border="0"> <tr> <td><b>Enter your name: </b></td> <td> <input type="text" size="15" name="j_username"> </td> </tr> <tr> <td><b>Enter your password: </b></td> <td> <input type="password" size="15" name="j_password"> </td> </tr> <tr> <td></td> <td align="right"> <input type="submit" value="Submit"> </td> </tr> <tr> <td><br></td> </tr> </table> </td> </tr> </table> </form> </center> </html> ', '_rc' => '200', '_headers' => bless( { 'connection' => 'close', 'x-powered-by' => [ 'Servlet/2 +.4', 'JSP/2.0' ], 'client-response-num' => 1, 'set-cookie' => 'JSESSIONID=27 +CCB71220635A381F38052A601A5C33; Path=/xyzSecureUpLoad_III; Secure', 'date' => 'Mon, 01 Mar 2004 17 +:43:47 GMT', 'client-ssl-cert-issuer' => '/ +C=US/ST=California/L=Santa Clara/O=Sun Microsystems/OU=SunONE/CN=S1AS +', 'client-ssl-cipher' => 'EDH-RS +A-DES-CBC3-SHA', 'client-peer' => 'localhost:10 +43', 'content-length' => '661', 'client-date' => 'Mon, 01 Mar +2004 17:43:47 GMT', 'content-type' => 'text/html;c +harset=ISO-8859-1', 'client-ssl-warning' => 'Peer +certificate not verified', 'client-ssl-cert-subject' => ' +/C=US/ST=California/L=Santa Clara/O=Sun Microsystems/OU=SunONE/CN=S1A +S', 'server' => 'Sun-Java-System/A +pplication-Server-PE-8.0', 'title' => 'xyz Secure HTTP Fi +le Uploader (ASHFU) Logon' }, 'HTTP::Headers' ), '_msg' => 'OK', '_request' => bless( { '_content' => 'j_username=TEST +001&j_password=TEST001&submit=Submit', '_uri' => bless( do{\(my $o = +'https://localhost:1043/xyzSecureUpLoad_III/logon.jsp')}, 'URI::https +' ), '_headers' => bless( { 'user-a +gent' => 'libwww-perl/5.69', 'conten +t-type' => 'application/x-www-form-urlencoded', 'conten +t-length' => 51 }, 'HTTP: +:Headers' ), '_method' => 'POST' }, 'HTTP::Request' ) }, 'HTTP::Response' ); ] do_logon END myscript.pl[289]
... to ...my $loginurl = "$url/logon.jsp";
But when I do that I get this HTML ...my $loginurl = "$url/j_security_check";
Anyone know what that is all about?HTTP Status 400 - Invalid direct reference to form login page type Status report message Invalid direct reference to form login page description The request sent by the client was syntactically incorrect + (Invalid direct reference to form login page). J2EETM 1.4 Application Server
| Plankton: 1% Evil, 99% Hot Gas. |
20040301 Edit by Corion: Changed PRE tag around server response to CODE to remove the page-widening
20040301 Edit by jdporter: added <readmore> tags
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: LWP and j_security_check form-based login?
by Abigail-II (Bishop) on Mar 01, 2004 at 19:17 UTC | |
|
Re: LWP and j_security_check form-based login?
by webengr (Pilgrim) on Mar 01, 2004 at 22:25 UTC | |
|
Re: LWP and j_security_check form-based login?
by inman (Curate) on Mar 02, 2004 at 13:11 UTC | |
|
Re: LWP and j_security_check form-based login?
by Plankton (Vicar) on Mar 01, 2004 at 23:20 UTC |