package LWP::Simple::Post; use strict; use warnings; use HTTP::Request::Common; sub import { my $pkg = shift; my $callpkg = caller; require LWP::Simple; push @LWP::Simple::EXPORT, qw(post postprint poststore); } sub LWP::Simple::post ($;%) { my $url = shift; my $ret; LWP::Simple::_init_ua() unless $LWP::Simple::ua; my $request = POST $url, Content_Type => 'form-data', Content => [ @_ ]; my $response = $LWP::Simple::ua->request($request); return $response->is_success ? $response->content : undef; } sub LWP::Simple::postprint ($;%) { my $url = shift; LWP::Simple::_init_ua() unless $LWP::Simple::ua; my $request = POST $url, Content_Type => 'form-data', Content => [ @_ ]; local $\ = ""; # ensure standard $OUTPUT_RECORD_SEPARATOR my $callback = ($^O ne 'MacOS' ? sub { print $_[0]; } : sub { $_[0] =~ s/\015?\012/\n/g; print $_[0]; }); my $response = $LWP::Simple::ua->request($request, $callback); unless ($response->is_success) { print STDERR $response->status_line, " <URL:$url>\n"; } return $response->code; } sub LWP::Simple::poststore ($$;%) { my $url = shift; my $file = shift; LWP::Simple::_init_ua() unless $LWP::Simple::ua; my $request = POST $url, Content_Type => 'form-data', Content => [ @_ ]; my $response = $LWP::Simple::ua->request( $request, $file ); return $response->code; } 1; __END__ =head1 NAME LWP::Simple::Post - adds the post method to LWP::Simple =head1 SYNOPSIS use LWP::Simple::Post; use LWP::Simple; poststore 'http://www.perlmonks.org', 'myfile.xml', node => 'diotalevi', displaytype => 'xml'; post 'http://www.perlmonks.org', node => 'diotalevi'; postprint 'http://www.perlmonks.org', node => 'diotalevi', displaytype => 'xml'; =head1 DESCRIPTION This module tacks the post(), postprint(), and poststore() functions o +nto LWP::Simple. =over 4 =item post($url, Header => Value,...) The post() function will fetch the document identified by the given UR +L and return it. It returns C<undef> if it fails. The $url argument ca +n be either a simple string or a reference to a URI object. The remainin +g arguments are a list of parameters to pass as form data. You will not be able to examine the response code or response headers (like 'Content-Type') when you are accessing the web using this function. If you need that information you should use the full OO interface (see L<LWP::UserAgent>). $url = 'http://www.perlmonks.org'; %parameters = ( node => 'Offering Plate ); post $url, %parameters; =item postprint($url, Header => Value,...) Post and print a document identified by a URL. The document is printed to STDOUT as data is received from the network. If the request fails, then the status code and message are printed on STDERR. The return value is the HTTP response code. =item poststore($url, $file, Header => Value,...) Store the document identified by a URL and stores it in the file. The return value is the HTTP response code. =back =head1 NOTES Be sure to use() LWP::Simple::Post before loading LWP::Simple. This mo +dule must extend LWP::Simple exports its own methods. =head1 SEE ALSO L<LWP::Simple>, L<HTTP::Request::Common> =head1 AUTHOR Joshua b. Jore E<lt>jjore@cpan.orgE<gt> =cut

In reply to LWP::Simple::Post - adds the post method to LWP::Simple by diotalevi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.