inblosam has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to mimic a form on a JSP site using LWP. The action attribute of the HTML form has the value of "/servlet/com.hhc.fileinfo" and the page's name is "fileinfo.jsp" (same as last bit of the action value, just with .jsp). I am trying to do an LWP post and send a file to upload just like the form allows me to, but I get this error message:

500 Internal Server Error com.hhc.ProductAdminFileInfo: java.io.IOException: Malformed line after disposition: Content-Length: + 15819

I try just submitting to the .jsp file of the page, but that doesn't work (returns me the page with just the form I submitted (there are multiple forms on the page). I don't know JSP well enough to understand what is going on. I have another script almost exactly similar (but for another site altogether) to this one that is posting files, but nothing else. Any ideas or help? Here is my code.

#!/usr/lib/perl use strict; use warnings; use Crypt::SSLeay; use LWP::UserAgent; use HTTP::Request::Common; use HTTP::Cookies; use LWP::Simple; my $ua = LWP::UserAgent->new; $ua->agent("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; Q312461 +)"); $ua->cookie_jar(HTTP::Cookies->new(file => 'cookie_jar', autosave =>1) +); push @{ $ua->requests_redirectable }, 'POST'; $ua->request(POST "http://www.somejspsite.com/user_login.jsp", { username => 'test123', password => 'test', go => 'Log In', }); my $request = $ua->request(POST "https://www.somejspsite.com/servlet/c +om.hhc.fileinfo", Content_Type => 'multipart/form-data', Content => [ productId =>"34234", home =>"BLAH", file =>["@env{DOCUMENT_ROOT}/files/image.gif"], go =>"Upload" ]); $b = $request->as_string; print $b;

Replies are listed 'Best First'.
Re: LWP on JSP site...
by moxliukas (Curate) on Jul 24, 2002 at 07:36 UTC

    You might want to to look at HTML::Form module, that does the form submission for you.

    The usage of HTML::Form is pretty simple and it parses all the methods and action tags automatically for you, also making the form submission as easy as calling $form->click;

      Using of HTML::Form unlikely to fix a problem as this module internally uses LWP::UserAgent.

      I'm not sure but this problem could be related to new HTTP/1.1 support code in latest versions of LWP. You may try to set environment variable PERL_LWP_USE_HTTP_10 before running your script. See perldoc LWP for details.

      --
      Ilya Martynov (http://martynov.org/)

        I tried doing so, but no change. Any other ideas?

        Michael Jensen