develooper Front page | perl.libwww | Postings from January 2001

LWP::UserAgent. Can't call method "request" on an undefined value at ???? what is causing this error in the cgi?

From:
Robert
Date:
January 15, 2001 14:14
Subject:
LWP::UserAgent. Can't call method "request" on an undefined value at ???? what is causing this error in the cgi?
Message ID:
006801c07f3f$8dfbf1e0$1a6001cb@chalmers.com.au

I have a test.pl program working, basically the standard example with
a few extras. It works fine as a stand alone program, but fails as a
subroutine in a cgi? and I can't understand why
-======================
#!/usr/local/bin/perl
use LWP::UserAgent;
$ua = new LWP::UserAgent;
$ua->agent("AgentName/0.1 " . $ua->agent);
#create request
my $req = new HTTP::Request POST => 'https://sec.aba.net.au/cgi-
bin/service/authorise/test';
$req->content_type('application/x-www-form-urlencoded');
$req->content('&secParams=https://sec.aba.net.au/merchant/test/testpayment.p
rops &referenceID=xxx &cardType=ABA Test &cardNumber=abasuccess
&nameOnCard=Robert &expiryMonth=3 &expiryYear=2002 &amount=45.00
&resultURL=http://www.chalmers.com.au/~robert/allvars.php3');
#Pass request and get response
my $res = $ua->request($req);
#Check response
if ($res->is_success) {
   print $res->content;
} else {
   print $res->status_line;
}

=======================
This works fine, and returns the output of the resultURL as requested.

HOWEVEr.....  if I put that routine into a perl CGI, and it gets
called from a generated web page, (Verify.html) like this,
 <form post.... ../../reg_system.cgi&action=esecpay>

I get this error message:
Can't call method "request" on an undefined value at
/usr/local/lib/perl5/site_perl/5.6.0/LWP/UserAgent.pm line 227.
========================================
sub esecpay {

   [ the same code as above, just without the /usr/local/bin/perl of
course]

}
==========================


This is the trace in its entirety from the perl script unsuccessfully called
via the cgi program.

LWP::UserAgent::new: ()
LWP::UserAgent::request: ()
LWP::UserAgent::simple_request: POST
https://sec.aba.net.au/cgi-bin/service/authorise/test
LWP::UserAgent::_need_proxy: Not proxied
LWP::Protocol::http::request: ()
Can't call method "request" on an undefined value at
/usr/local/lib/perl5/site_perl/5.6.0/LWP/UserAgent.pm line 227.

===============================

This is the top part of the _successful_ run from just the perl program.
(command line)
LWP::UserAgent::new: ()
LWP::UserAgent::request: ()
LWP::UserAgent::simple_request: POST
https://sec.aba.net.au/cgi-bin/service/authorise/test
LWP::UserAgent::_need_proxy: Not proxied
LWP::Protocol::http::request: ()
LWP::Protocol::http::request: POST /cgi-bin/service/authorise/test
HTTP/1.0
Host: sec.aba.net.au
User-Agent: AgentName/0.1 libwww-perl/5.50
=============================

Both bits of code are exactly the same. The one in the cgi as a subroutine
fails, the command line script works.

Can anyone shed some light on this at all - you'll have a friend for life:-)

thanks
Robert





nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About