Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: POSTing with LWP::UserAgent

by chipmunk (Parson)
on Jan 08, 2001 at 02:30 UTC ( #50399=note: print w/replies, xml ) Need Help??

in reply to POSTing with LWP::UserAgent

The lwpcook documentation (that comes with the LWP bundle) provides very helpful examples of how to use the LWP modules. Here's the section on POSTing data:
POST There is no simple procedural interface for posting data to a WWW serv +er. You must use the object oriented interface for this. The most common POST operation is to access a WWW form application: use LWP::UserAgent; $ua = new LWP::UserAgent; my $req = new HTTP::Request 'POST',' +limpse'; $req->content_type('application/x-www-form-urlencoded'); $req->content('match=www&errors=0'); my $res = $ua->request($req); print $res->as_string; Lazy people use the HTTP::Request::Common module to set up a suitable POST request message (it handles all the escaping issues) and has a suitable default for the content_type: use HTTP::Request::Common qw(POST); use LWP::UserAgent; $ua = new LWP::UserAgent; my $req = POST '', [ search => 'www', errors => 0 ]; print $ua->request($req)->as_string; The lwp-request program (alias POST) that is distributed with the library can also be used for posting data.
I've used the lazy approach to good effect.

Replies are listed 'Best First'.
Re: Re: POSTing with LWP::UserAgent
by Intaglio (Novice) on Jan 08, 2001 at 02:35 UTC
    Ah the lazy approach looks pretty good to me as well =)

    Thanks, where did you find this? The only place I located any information on LWP was at

      Into a command prompt type:
      perldoc perldoc
      and you will learn how to get documentation of Perl things installed on your system. Not to be underestimated is that you get documented the version that you actually have installed. And if you become competent (which is mainly a question of learning to use "/pattern" then "n") at finding stuff in those pages you will generally find it faster to find things in that documentation than through websites.
        Note that you actually need perldoc installed to use the perldoc command. Unfortunately, some Linux distributions (like Mandrake) don't come with perldoc installed by default. (Note: I followed the random node link. You probably already have perl doc installed)

        Want to support the EFF and FSF buy buying cool stuff? Click here.
      You can find the lwpcook documentation on by typing lwpcook into the search box. lwpcook is an LWP CookBook; it contains "recipes" for common tasks involving LWP that you can use in own code.

      On your own system, since you have LWP installed, you should be able to read the lwpcook documentation by typing perldoc lwpcook on the command line.

      davorg wrote a good series of articles in Perl Month explaining how to get documentation using the command perldoc.

      They start in Issue #1

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://50399]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2018-07-17 21:44 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (378 votes). Check out past polls.