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

Hello wise monks.

What is the difference between the POST command used on the UNIX command line, and the POST command in the LWP::UserAgent module? How can I emulate the following snippet at the command line in perl code?:

cat topup.txt | POST https://xxx.xxx.xx.xxx/portal/webservices.cgihttps://xxx.xxx.xx.xxx/portal/webservices.cgi

Thanks in advance.

Raymond

Replies are listed 'Best First'.
Re: POST and POST
by b10m (Vicar) on Feb 11, 2004 at 10:00 UTC

    Did you actually examine the POST command you have on your UNIX system? ;)

    $ head /usr/local/bin/POST #!/usr/local/bin/perl -w eval 'exec /usr/local/bin/perl -w -S $0 ${1+"$@"}' if 0; # not running under some shell # $Id: lwp-request,v 2.6 2003/10/26 14:39:18 gisle Exp $ # # Simple user agent using LWP library. =head1 NAME

    So yeah, it's just a simple Perl script that uses the LWP module. See perldoc /usr/local/bin/POST for the POD on that (please note: on my system, POST is located in /usr/local/bin. On your system it could be different, but a simple which POST will show you the location).

    --
    b10m

    All code is usually tested, but rarely trusted.

      Presuming that it's in your PATH just a simple perldoc POST should find it.</pedant>

      And perldoc lwpcook would also be of interest.

Re: POST and POST
by edan (Curate) on Feb 11, 2004 at 10:03 UTC

    Perhaps the following code snippet will help you get going in the right direction. It needs a lot of error-checking (it's not intended to be a robust solution, just a starting point).

    #!/usr/bin/perl use strict; use warnings; use LWP::UserAgent; use HTTP::Request; $/ = undef; #slurp; my $content = <STDIN>; my $uri = shift; # arg my $method = 'POST'; my $request = HTTP::Request->new($method, $uri, undef, $content); my $ua = LWP::UserAgent->new(timeout => 10); my $response = $ua->request($request); if ($response->is_success) { print $response->content; } else { print $response->error_as_HTML; }
    --
    edan (formerly known as 3dan)

Re: POST and POST
by Abigail-II (Bishop) on Feb 11, 2004 at 11:02 UTC
    Something like this (untested):
    perl -MLWP::UserAgent -wle 'print LWP::UserAgent -> new -> post ("https://xxx.xxx.xx.xxx/portal/webservices.cgi", [`cat topup.txt`]) -> content'

    Abigail