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

I'm attempting to write to a web server file from a Perl program (ActiveState 5.10) on my Windows XP laptop.

The program seems to run but the file isn't updated. So I'm working on validating the success for failure, displaying the response, understand the security issue at the server level.
Any one want to jump in and add any wisdom that would be great:
1) am I headed in the right direction? I read PUT is less used but more efficient than POST.
2) what's the best way of displaying the response and catching errors?
3) What's the Linux host permissions need to be set at?

4) Can I PUT one file to another?


Code:

use HTTP::Request;
my $request = new HTTP::Request 'PUT', 'http://mysite.com/runstats/ICD-2008.txt';
$request->header('content-length' => 26);
$request->header('content-type' => 'text/plain');
$request->content('xxxxxxxxxxxxxxxxxxxxxxxxxx');
print $request->as_string( );
my $code;
my $msg;
my $header;
my $content;
my $r;
$r = HTTP::Response->new( $code, $msg, $header, $content );
print "\n $r \n";
my $str;
$r = HTTP::Response->parse( $str );
print "\n $r \n";


-------------Response:
PUT http://mysite.com/runstats/ICD-2008.txt
Content-Length: 26
Content-Type: text/plain
xxxxxxxxxxxxxxxxxxxxxxxxxx
HTTP::Response=HASH(0x1b5d4fc)
HTTP::Response=HASH(0x1b5d63c)

Replies are listed 'Best First'.
Re: HTTP::Request 'PUT'
by Corion (Patriarch) on Mar 09, 2008 at 08:41 UTC

    Are you sure that your webserver implements PUT at all? I think only the WebDAV extensions implement and handle PUT. Otherwise, without password protection, anybody could overwrite your files.

    If you want to see the text the server sends you back, use $r->as_string. This should give you an explanation of what happens, as should the webserver error logs.

Re: HTTP::Request 'PUT'
by peter (Sexton) on Mar 09, 2008 at 17:39 UTC
    1. What is the code that you use to write the file? The code you showed doesn't do that.
    2. Maybe your webserver doesn't allow PUT by default. If it doesn't you should enable it (and have a handler/module that processes the put. Apache can use the mod_actions module to handle PUTs.
    Peter Stuifzand
      Thanks for the help Peter, The file is an existing .txt file with some data in it. I'll check to see if the website PUT is enabled. kc