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;

In reply to LWP on JSP site... by inblosam

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.