Gorby has asked for the wisdom of the Perl Monks concerning the following question:

Hello Wise Monks. I'm sorry for being so ignorant, but how do you send execute POST requests using LWP::Simple? I know how to execute GET requests, but can you give me an example of how to do a POST request with parameters like foo=test1&bar=test2?

Thanks in advance.

Gorby

Replies are listed 'Best First'.
Re: POST on LWP::Simple
by Abigail-II (Bishop) on Feb 08, 2004 at 18:20 UTC
    You don't. Either use LWP::UserAgent, or the POST (or lwp-request) utility that comes with LWP. As the description of LWP::Simple says:
    This module is meant for people who want a simplified view of the libwww-perl library. It should also be suitable for one-liners. If you need more control or access to the header fields in the requests sent and responses received, then you should use the full object-oriented interface provided by the "LWP::UserAgent" module.

    Abigail

      How then do I use POST using LWP::UserAgent? Can you give an example? Thanks. Gorby.

        Straight from lwpcook:

        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 = LWP::UserAgent->new; my $req = POST 'http://www.perl.com/cgi-bin/BugGlimpse', [ search => 'www', errors => 0 ]; print $ua->request($req)->as_string;
        How then do I use POST using LWP::UserAgent?
        Did you bother to read the documentation of LWP::UserAgent? If so, could you indicate which part about using POST was unclear to you?

        Abigail

Re: POST on LWP::Simple
by diotalevi (Canon) on Feb 11, 2004 at 00:20 UTC