Re: Problem with LWP||UserAgent

Bob Gustafson (bobgus@mcs.com)
Thu, 23 Mar 2000 17:13:44 -0600


Hi

1) if the program testparam.pl is as listed immediately below

#!/usr/local/bin/perl
# testparam.pl

use CGI;

$q = new CGI;

# echo back the parameters

print $q->header;
print $q->start_html;
print $q->as_string;
print $q->end_html;



Then if your program below is called debug.pl and you call it from a
command line, then everything seems to work OK and you will get the
response:

#./debug.pl

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
Untitled Document 2) if the program testparam.pl is as above and your program below is debug.pl and is also in the cgi-bin directory, then if you call debug.pl from your browser, you will get a 500 error because your program below does not set up a proper header to show the above response on the browser. 3) If you just call testparam.pl from your browser, then you will get a blank screen with a title 'Untitled Document'. This is correct because you did not provide testparam.pl with any parameters. 4) if you call testparam.pl?what=good from your browser, then you will get a return screen with a bold face what followed by another line with good. I hope this helps. BobG >I am having a problem POSTing or GETting data. I am using the LWP::UserAgent >module. Here is the code that I am executing and the error that I get. > >use URI::URL; >use LWP::UserAgent; >use HTTP::Request; >use HTTP::Response; > >$ua = new LWP::UserAgent; >$ua->agent("Mozilla/2.0"); >$req = new HTTP::Request 'POST', 'http://some.fix.ip/cgi-bin/testparam.pl'; >$req->content_type('application/x-www-form-urlencoded'); >$curl = url('http:'); >$curl->query_form(action => 'add', login => 'a10'); >$req->content($curl->equery); >$res = $ua->request($req); > >if ($res->is_success) { > print $res->content; >} else { > print $res->as_string(); >} >exit(0); > > >This is the error that I get >500 (Internal Server Error) Modification of a read-only value attempted ... > >When I call the same script (testparam.pl) from a browser, it works fine. >What could be wrong here ??? Urgent. Please Help . > >Thanks! >Abhin Parkhi