views:

473

answers:

1

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?

+3  A: 

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 of form-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.

Sinan Ünür
What do you mean exactly? I define the Content_Type asd 'form-data' at line 5
goe
"form-data" != "multipart/form-data"
David Dorward
Well, I took this example from: "http://kobesearch.cpan.org/htdocs/libwww-perl/HTTP/Request/Common.pm.html#POST_url_Header_gt_Value_Content_gt_" and they use "form-data" plus there' no comma between POST and the actual URL
goe
OK, I'm using $ua->post now. Since I'm trying to post the request within the same application is there a way to use the relative path for the url like: $ua->post('testing.nc') , when I tried that I get the "path has to be absolute" in the response.
goe