Hello, I've read various posts regarding HTTP posting and I even have a nice working example (below). The problem I am having may be on the cgi side of things but I'm unsure. The server accepts the HTTP post and even sends back a message in the result stating that the file I've uploaded is now available for download and gives the URL. However, the getting the URL returns 404. I am suspicious that maybe I'm uploading the filename path, but not the actual file data hence fooling the cgi engine serverside. For the curious, I'm uploading a file to have it digitally signed, and then presented for download post signing. Does my code have any glaring issues?
#!/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 }

In reply to Am I HTTP posting a file correctly? by mikelupo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.