I'm trying to post from one of my subroutines in Perl a request to a Java based controller. But I'm not getting any kind of response back. I know the Java code works file because I can get a response if I post to it from a HTML form.
This is my Perl code:
use HTTP::Request::Common;
my $ua = LWP::UserAgent->new;
my $response = $ua->request(POST 'http://testserver/testing.nc',
Content_Type => 'form-data',
Content => [
method => 'submit',
ftp_server => 'ftp.localhost',
ftp_user => 'testuser',
ftp_password => 'testpass',
remote_path => '/home/files',
port => 22,
file_to_upload => ["$file"]
]);
Is there something wrong with this code?
Posted data must be of type multipart/form-data
.
Edit: OK, so it turns out, specifying form-data
is enough as mentioned in the HTTP::Request::Common docs:
The POST method also supports the
multipart/form-data
content used for Form-based File Upload as specified in RFC 1867. You trigger this content format by specifying a content type ofform-data
as one of the request headers.
However, to use HTTP::Request::Common::POST
the way you are using, you will need to import POST
:
use HTTP::Request::Common qw(POST);
or use $ua->post
:
The
post(...)
method of LWP::UserAgent exists as a shortcut for$ua->request(POST ...)
.
You can make your life easier by using WWW::Mechanize. See also this upload example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With