Am Montag, 9. Mai 2005 20.28 schrieb Jason Williard:
> I am trying to write a script that will post a file to another script on
> another server via HTTP::Request.  I seem to be unsuccessful and was
> hoping that someone could point out my mistakes.  Here is the code that
> I have so far:
>
> ---------------------------

[not tested]

> #!/usr/bin/perl -W 

instead of the -W switch:

use strict;
use warnings;

> use HTTP::Request;
> use HTTP::Response;
> use LWP::UserAgent;
>
> my $ua = new LWP::UserAgent;
> $ua->agent("Uploader/0.1 " . $ua->agent);

The ". $ua->agent" part is not necessary if the string before ends with a 
space.

> my $url  = "http://my.url/upload.pl";;
> my $base = "/www/htdocs/base";
>
> my $request = HTTP::Request->new(POST $url);

At least there is a comma missing between the two arguments to new().
If POST ist not a (imported) constant, put it in quotes.

> $request->content_type('form-data');
> $request->content( [    mirror  => 'download01',
>                          file    => ["$base/File.exe"],
>                     ]
> );

According to the man pages of HTTP::Request and HTTP::Message, the content() 
method takes a string of bytes as argument.

> my $response = $ua->request($request);
>
> if ( $response->is_success ) {
>          print $response->content;
> } else {
>          print "No Good\n";
> }
> ---------------------------

What you can do further:

- Inspect the warnings/errors you get when running the code
- Test if the objects get created
- Inspect the objects structure with Data::Dumper
- put some print statements in the code to inspect variables

joe

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to