in reply to Submitting information to an online form

UPDATE prepare to dopeslap yourself -- I bet the root problem is that you've misspelled the name of the module HTTP::Headers -- note the 's' on the end! So make that change and go back to your old code. BTW this also makes sense of the error message; the Request object expects the third argument to be an anonymous array of an HTTP::Headers object and an anonymous array of the content, i.e. [$header, [$content]] ... the way it is now, it sees first the reference to the array whose sole member is $content, and that's not a blessed reference.

bless is a perl function that's used in Object oriented programming -- you use it to 'bless' an object into a class, to mark it as an object (rather than a plain ol' reference). The basic idea is that a reference must be *blessed* before you can call *methods* on it, and somwhere inside HTTP:Message, something that's not an object (because it hasn't been blessed) is being treated as if it were.

What's going on is that one of the modules you are using uses HTTP::Message internally -- and there are a couple of candidates here (HTTP:::Request is a subclass of HTTP::Message) -- and you've subtly messed up a call to a constructor. I'm not feeling generous enough with my time to track down *which* one for you, but go over the documentation for the objects you're instantiating and make sure those calls pass in the right kinds of arguments.

I'm not sure you need to explicitly use all those modules, either. Try it with just use LWP::UserAgent left in there and see if that works. It may even solve your problem.

Side note: when you get errors you don't understand, you can often get a lot more info by calling perldoc perldiag and searching for (the generic part of) your error message. Similar results can be obtained by putting use diagnostics at the top of your script.

Replies are listed 'Best First'.
Re: Re: Submitting information to an online form
by arturo (Vicar) on Apr 25, 2001 at 17:26 UTC

    response to myself ... you don't need HTTP::Headers at all. Here's working code, culled from perldoc lwpcook and modified to fit your example (note, the only module you explicitly have to use is LWP::UserAgent) :

    #!/usr/bin/perl -w use strict; use LWP::UserAgent; my $ua = LWP::UserAgent->new(); my $req = HTTP::Request->new(POST=>'http://212.87.65.227/bin/query.exe +/en'); $req->content_type('application/x-www-form-urlencoded'); $req->content('to=Guildford&from=Portsmouth'); my $res = $ua->request($req); if ($res->is_success) { print $res->content; } else { print "Error: ", $res->status_line, "\n"; }