UPDATE:

Thank Mortiz and Ikegami. This issue is now resolved, this code works:

#!/usr/bin/perl use strict; use warnings; use LWP::UserAgent; use HTTP::Request::Common qw( POST ); use Data::Dumper; my $ua = LWP::UserAgent->new(); my $url = 'http://lobitos.net/cgi-sys/cgiwrap/jlundell/stv-count.py'; my $ballot_file = '/home/hesco/foo/bar/ballot_file.txt'; my $response = $ua->request(POST $url, Content_Type => 'multipart/form-data', Content => [ datafile => [ $ballot_file ], action => 'Count', ], ); # print Dumper($response->{'_content'}); print Dumper($response->content()); 1;
. . . and my original question:


I'm working to upload a file to a webform with LWP. Following a pointer from Utilitarian, shared in the cb, I read this thread and am working to adapt code from there (although some of it looks like narley and required some work just to compile). Nonetheless it seems I'm on to something here.

And my question, what am I missing here?

My test script reads:

#!/usr/bin/perl use strict; use warnings; use LWP::UserAgent; use Data::Dumper; my $ua = LWP::UserAgent->new(); my $url = 'http://lobitos.net/cgi-sys/cgiwrap/jlundell/stv-count.py'; my $ballot_file = '/home/hesco/foo/bar/ballot_file.txt'; my $request = ( # POST => $url, action => 'Count', name => 'datafile', Content_Type => 'multipart/form-data', Content => [ 'file' => [ $ballot_file ]] ); my $response = $ua->post($url,$request); print Dumper($response); 1;
And the form I'm posting against reads:

<form action="/cgi-sys/cgiwrap/jlundell/stv-count.py" enctype="multipa +rt/form-data" method="post"> <p>Specify an election file: <input type="file" name="datafile" size=" +40"><br> then <input type="submit" name="action" value="Count"></p> </form>
My output reads:

hesco@marcus8:~$ perl GP/GPotUS/2009/ETC/lib/upload_test.pl Useless use of a constant in void context at lib/upload_test.pl line 1 +5. Useless use of a constant in void context at lib/upload_test.pl line 1 +5. Useless use of a constant in void context at lib/upload_test.pl line 1 +5. Useless use of a constant in void context at lib/upload_test.pl line 1 +5. Useless use of a constant in void context at lib/upload_test.pl line 1 +5. Useless use of a constant in void context at lib/upload_test.pl line 1 +5. Useless use of a constant in void context at lib/upload_test.pl line 1 +5. $VAR1 = bless( { '_protocol' => 'HTTP/1.1', '_content' => 'no field \'datafile\'', '_rc' => '200', '_headers' => bless( { 'client-date' => 'Thu, 17 Sep 2009 06:24:54 GMT', 'content-type' => 'text/plain', 'connection' => 'close', 'client-response-num' => 1, 'date' => 'Thu, 17 Sep 2009 06:25:35 GMT', 'client-transfer-encoding' => [ 'chunked' ], 'client-peer' => '216.92.168.130:80', 'server' => 'Apache/2.2.13' }, 'HTTP::Headers' ), '_msg' => 'OK', '_request' => bless( { '_content' => 'file=%2Fhome%2Fhesco%2Ffoo%2Fbar%2Fballot_file.txt' +, '_uri' => bless( do{\(my $o = 'http://lobitos.net/cgi-sys/cgiwrap/ +jlundell/stv-count.py')}, 'URI::http' ), '_headers' => bless( { 'user-agent' => 'libwww-perl/5.830', 'content-type' => 'application/x-www-form-urlencoded', 'content-length' => 50 }, 'HTTP::Headers' ), '_method' => 'POST', '_uri_canonical' => $VAR1->{'_request'}{'_uri'} }, 'HTTP::Request' ) }, 'HTTP::Response' ); hesco@marcus8:~$
And here is a sample ballot file to play with:

title=Elect Your Favoprite Ice Cream seats=4 threshold=droop threshold=strict verbose=3 random=37863 candidate=1 Rocky Road candidate=2 Chocolate candidate=3 Strawberry Sherbert candidate=4 Cinnamon Swirl candidate=6 Peanut Butter Fudge candidate=8 Pralines and Cream candidate=9 Cookies and Cream candidate=10 Pecan Sandies candidate=12 Vanilla ala Mode candidate=13 Strawberry Shortcake candidate=14 Popsickles candidate=15 Vanilla candidate=17 Moose Tracks candidate=20 Ice Cream Sandwiches candidate=21 Fudgecycles candidate=22 Frozen Puppies candidate=23 Homemade candidate=24 Truffles candidate=11 None of the above ballots=113 4 3 1 2 6 6 1 4 2 3 1 6 8 4 1 4 3 2 1 4 2 3 6 1 2 3 4 8 9 17 6 1 3 4 2 8 4 3 1 6 8 1 4 2 3 6 3 4 1 1 6 3 4 2 8 4 3 1 2 3 1 2 4 6 1 3 4 2 6 6 1 2 8 3 23 4 1 3 2 6 8 4 3 1 1 6 3 4 2 8 6 20 14 2 1 4 3 4 1 3 2 2 4 1 3 6 1 4 3 6 3 1 4 2 8 1 4 2 6 3 8 6 8 2 1 1 4 2 3 6 1 3 4 2 1 4 3 6 10 1 3 4 3 4 2 1 8 6 1 4 3 2 1 8 2 3 4 1 3 2 1 2 4 3 6 4 6 1 3 2 8 12 10 1 3 2 4 8 6 8 1 2 4 3 1 6 2 4 3 8 1 2 3 1 4 6 2 4 3 1 2 6 4 1 3 6 2 8 6 21 22 3 4 1 2 4 1 6 1 4 3 2 8 6 3 8 2 1 6 4 1 1 2 4 3 6 3 1 4 6 2 4 3 1 6 2 8 1 2 3 4 6 2 3 1 1 4 2 6 8 1 6 1 4 13 1 2 3 4 1 3 6 2 1 2 6 4 3 8 6 3 2 8 4 1 6 1 4 3 2 1 3 2 6 4 1 8 3 2 4 3 1 6 2 4 1 2 3 6 12 10 4 3 1 6 1 6 2 4 1 6 2 3 4 8 4 1 3 6 2 1 4 3 2 6 1 4 3 2 8 1 6 1 3 4 2 3 1 4 2 13 4 1 2 3 6 4 6 1 6 2 4 1 1 4 6 8 2 3 1 4 3 6 2 4 1 8 6 3 2 4 3 1 2 4 1 3 2 6 11 8 1 4 3 2 1 6 1 4 3 2 6 3 1 4 2 8 6 3 1 2 4 8 6 3 1 8 2 6 2 8 1 3 4 1 4 2 3 1 4 8 6 3 1 4 6 6 8 3 1 2 1 8 2 6 3 4 3 4 2 1 1 3 4 2 6 4 1 3 2 6 15 3 2 4 6 1 1 4 3 6 2 6 8 2 1 3 4 4 3 1 2 4 1 3 2 6 8 8 6 1 2 4 2 1 3 1 3 4 2 6 8 1 8 2 4 3 1 2 2 4 3 1 4 3 2 1 6 1 3 4 2 8 6 4 3 1 6 2 8 3 1 6 4 end
if( $lal && $lol ) { $life++; }
if( $insurance->rationing() ) { $people->die(); }

In reply to Seek help posting to www-form-urlencoded . . . by hesco

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.