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

All, I need some help with setting up a script to do a http PUT of a xml file to a URL that uses basic auth. Xml file will be different each time. Could someone take a look at what I have so far and let me know what's missing, or could be changed? I appreciate the help:
#!/usr/bin/perl -w use strict; use LWP::UserAgent; use HTTP::Request::Common; use URI::Escape qw( uri_escape ); my $uid = "user"; my $upw = "pass"; my $ua = LWP::UserAgent->new(agent => 'perl put'); $ua->credentials('host.com:80', '', $uid, $upw); my $message = "</path/file.xml"; my $response = $userAgent->request(PUT 'http://host.com/xml', Content_Type => 'text/xml', Content => $message); print $response->error_as_HTML unless $response->is_success; print $response->content();

Replies are listed 'Best First'.
Re: Help with HTTP POST xml file
by ccn (Vicar) on Nov 19, 2008 at 16:55 UTC
    use File::Slurp; my $message = read_file( '/path/file.xml' ) ;
      It actually needs to be a put. So im trying the below, but getting a 401 rejection even though it's basic auth. Is there a specific Mod I need to call for basic auth?
      use LWP::UserAgent; use HTTP::Request::Common; use URI::Escape qw( uri_escape ); use File::Slurp; use LWP::Debug qw(+); use Data::Dumper; my $uid = "id"; my $upw = "pass"; my $message = read_file( '/tmp/1.xml' ) ; my $ua = LWP::UserAgent->new(agent => 'perl put'); $ua->credentials('host.com:80', '', $uid, $upw); my $response = $ua->request(PUT 'http://host.com', Content_Type => 'text/xml', Content => $message); print $response->error_as_HTML unless $response->is_success; print $response->content();