mikelupo has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl # file: uploadafile.pl # call me like this: # uploadafile.pl --url=http://www.x.com/cgi-bin/upload.pl --uploadfile +=c:/temp/who.gif --sig=3rdparty|latest # use strict; use LWP::UserAgent; use HTTP::Request::Common; use Getopt::Long; use File::Basename; my ( $o_url, $o_fqn, $o_sver ); GetOptions( "url=s" => \$o_url, "uploadfile=s" => \$o_fqn, "sig=s" => \$o_sver, ); # mandatory arguments: url &usage unless ( $o_url && $o_fqn && $o_sver ); my $url = $o_url; my $fname = $o_fqn; my $sign = $o_sver; binmode $fname; open FILE, $fname or die $!; binmode FILE; my $buffer; read(FILE, $buffer, 20, 0); binmode $buffer; close(FILE); foreach (split(//, $buffer)) { printf("%02x ", ord($_)); print "\n" if $_ eq "\n"; } #my ($buf, $data, $n); #while (($n = read FILE, $data, 4) != 0) { # print "$n bytes read\n"; # $buf .= $data; #} # put timeouts, proxy etc into the useragent if needed my $ua = LWP::UserAgent->new(); my $req = POST $url, ENCTYPE => 'multipart/form-data', Content => [ submit => 'Sign', widget_bundle => [$fname], email_address => 'harish.krishnamurthy@nokia.com', signer_version => $sign, ]; my $response = $ua->request($req); close(FILE); if ($response->is_success()) { print "OK: ", $response->content; } else { print $response->as_string; } exit; sub usage { printf "usage: %s --url=%s --uploadfile=%s\\n", basename($0),'http://....','c:/data/myfile.jpg','3rdparty|late +st'; exit }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Am I HTTP posting a file correctly?
by locked_user sundialsvc4 (Abbot) on Nov 24, 2010 at 19:03 UTC | |
by mikelupo (Initiate) on Nov 26, 2010 at 19:07 UTC | |
by Corion (Patriarch) on Nov 26, 2010 at 19:20 UTC | |
by Anonymous Monk on Nov 26, 2010 at 19:42 UTC |