LWP::UserAgent. Can't call method "request" on an undefined value at ???? what is causing this error
Robert (robert@chalmers.com.au)
Tue, 16 Jan 2001 08:07:28 +1000
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