ashish srivastava wrote:

> hi,
> i am running the same script that u gave(with some minor modifications) but 
> i am unable to get the result e.g.

See modified scripts at end.

> main prog(to be automated):
> ----------------------------------------
> #!D:\perl\bin\perl
> 
> use CGI::Carp qw(fatalsToBrowser);
> require "./cgi-lib.pl";
> &ReadParse();
> 
> print "Content-type:text/html\n\n";
> print <<"HTML";
> <HTML>
> <HEAD><title> My LWP/Mechanize example</title></head>
> <body>
> <form name=text METHOD=POST actions=/cgi-bin/lwp1.pl>
> <input type=test name=f1 size=20>
> &nbsp&nbsp&nbsp&nbsp;
> <input type=password name=f2 size=20>
> <input type=submit name=f3 value=\"Submit\">
>   </form>
> HTML
> 
> $action=$in{'f3'};
> print "Action si : $action<br>";
> if ($action eq "Submit") {
>       $t1=$in{'f1'};
>       $t2=$in{'f2'};
>       print "Values passed are : <b>$t1&nbsp&nbsp&nbsp;$t2</b><br>";
> }
> ===========================================
> Script which automates it
> ----------------------------------
> #!D:\perl\bin\perl
> use CGI;
> use LWP::UserAgent
> $UA = LWP::UserAgent->new();
> 
> my $URL_Server = 'http://url.com/cgi-bin/lwp1.pl';
> my $username = 'ashish';
> my $password = 'srivastava';
> my %fields = (f1 => $username, f2 => $password);
> my $res = $UA->post($URL_Server,\%fields);
> #print "Success ? ".$res->is_success()."\n"."Success is $res\n";
> #print ($res->is_success) ? $res->content : $res->status_line;
> print $res->content();
> 
> This prints the entire HTML page
> ----------------------------------------------
> <HTML>
> <HEAD><title> My LWP/Mechanize example</title></head>
> <body>
> <form name=text METHOD=POST actions=/cgi-bin/lwp1.pl>
> <input type=test name=f1 size=20>
> &nbsp&nbsp&nbsp&nbsp;
> <input type=password name=f2 size=20>
> <input type=submit name=f3 value="Submit">
>   </form>
> Action si : <br>
> 
> ========================================
> What am i missing?

use LWP::UserAgent;
use HTTP::Request::Common qw(POST);

my $URL = 'http://url.com/cgi-bin/lwp1.pl';
my $username = 'ashish';
my $password = 'srivastava';
my %fields = (f1 => $username, f2 => $password, f3 => 'Submit');

my $UA = LWP::UserAgent->new();
my $req = POST $URL, \%fields;
my $res = $UA->request($req);
if ($res->is_success) {
        print $res->content();
} else {
        print $res->error_as_HTML();
}

__END__

use strict;
use CGI::Carp qw(fatalsToBrowser);
use CGI;

my $CGI = new CGI;

print <<HTML;
Content-type:text/html

<HTML>
<HEAD><title> My LWP/Mechanize example</title></head>
<body>
<form METHOD="POST" action="/cgi-bin/lwp1.pl">
Username: <input type="text" name="f1" size="20">
&nbsp&nbsp&nbsp&nbsp;
Pasword: <input type="password" name="f2" size="20">
<input type="submit" name="f3" value="Submit">
</form>
HTML

my $action = $CGI->param('f3');
print "<BR>Action is : $action\n";

if ($action eq "Submit") {
        my $t1 = $CGI->param('f1');
        my $t2 = $CGI->param('f2');
        print "<BR>Values passed are : <b>f1='$t1'; f2='$t2'</b>\n";
}

__END__


-- 
  ,-/-  __      _  _         $Bill Luebkert    Mailto:[EMAIL PROTECTED]
 (_/   /  )    // //       DBE Collectibles    Mailto:[EMAIL PROTECTED]
  / ) /--<  o // //      Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_</_</_    http://dbecoll.tripod.com/ (My Perl/Lakers stuff)

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to