2009/3/19 Dermot <paik...@googlemail.com>: > Hi, > > I can't see what I am doing wrong when I construct a request with > HTTP::Request::Common. I am trying to use the Form-based File-Upload > feature as described at > > http://search.cpan.org/~gaas/libwww-perl-5.825/lib/HTTP/Request/Common.pm > > > Here my code fragment: > > use 'Carp'; > BEGIN { use_ok( 'LWP::UserAgent' ); } > BEGIN { use_ok( 'HTTP::Request::Common' ); } > ... > > $url .= '/cgi-bin/uploadPDF.pl'; > > my $req = HTTP::Request->new(POST $url, Content_Type => 'form-data', > Content => [uploaded_file => $file_glob]); > > my $ua = LWP::UserAgent->new; > my $res = $ua->request($req); > $ua->timeout(90); > print STDERR "Send request for $url\n"; > if ($res->is_success) { > return($res->decoded_content); > } > else { > croak "Error from http request: ".$res->decoded_content." ".$res; > } > > > The error is: > > Send request for http://server.somedomain/cgi-bin/uploadPDF.pl > Error from http request: 400 URL missing > HTTP::Response=HASH(0x882e894) at t/05upload_pdf.t line 51 > main::upload_pdf('server.somedomain', '/path/to/mypdf.pdf') called at > t/05upload_pdf.t line 20 > # Looks like your test exited with 255 just after 3
Resolved, after a couple of frustrating hours First I have to update my LWP/HTTP::Request modules. Then read the documents a little closer. I noticed that 'Content' is not the only array. The file upload field is expects an array. my $req = HTTP::Request->new(POST $url, Content_Type => 'form-data', Content => [uploaded_file => $file_glob] ); # Wrong my $req = HTTP::Request->new(POST $url, Content_Type => 'form-data', Content => [uploaded_file => [ $file_glob] ] ); # Right Dp. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/