Thanks, that worked for a simple get and post.
How would you post multipart form data such as a file?
Can assume we've already got the post data in the %in hash.
So, how would we post multipart form data to another site?
Also, how's the stuff look below? It apears to work ok.
Reference:
# *************** Get example:
#!/usr/bin/perl
use Time::localtime;
use CGI::Enurl;
use LWP::Simple;
# Create a user agent object
use LWP::UserAgent;
$ua = LWP::UserAgent->new;
$ua->agent("MyApp/0.1 "

;
# Create a request
$req = HTTP::Request->new(GET => '
# establish authentication credentials
# NOTE:
# To locate needed info for call to credentials, from
# command-line:
#lwp-request -e -a
#
$ua->credentials(
'desintationSite.com:80',
'Ream name goes here - ie. name of site appearing as realm in Apache authentication window.',
'username' => 'password'
);
# send request
$res = $ua->request($req);
# check the outcome
if ($res->is_success) {
print $res->content;
#print $res->as_string;
} else {
#print $res->content;
print "Error: " . $res->status_line . "\n";
# For a post:
print '**************Post with LWP*********************\n';
my ($content, $messasge, $is_success) = do_POST('
[ 'key1' => "value1", 'key2' => "value2" ],);
print "2:".$content if $is_success;
print "3:".$message;
#==========================
# do_POST
#==========================
sub do_POST {
use LWP;
# Parameters:
# the URL,
# an arrayref or hashref for the key/value pairs,
# and then, optionally, any header lines: (key,value, key,value)
my $browser; # good to have this as local var here?
$browser = LWP::UserAgent->new( ) unless $browser;
$browser->credentials(
'sitename.com:80',
'Realm goes here again',
'username' => 'password'
);
my $resp = $browser->post(@_);
return ($resp->content, $resp->status_line, $resp->is_success, $resp)
if wantarray;
return unless $resp->is_success;
return $resp->content;
}