BTW, HTML::Form objects also have a click() method, which returns an HTTP::Request object (in contrast to $mech->click(...), which returns an HTTP::Response object). And the HTTP::Request object has an as_string() method, that can be used to debug such things without doing tcpdumps (or even actually sending the request). For example:

use HTML::Form; my $html = <<'EOHTML'; <html> <body> <form action="http://localhost/" method="POST" enctype="multipart/form +-data"> <input type="file" name="file_name" value="test.csv" /> <input type="Submit" name="submit" value="Submit" label="Sumbit" /> </form> </body> </html> EOHTML my $form = HTML::Form->parse($html, "/"); # that would be something like $form = $mech->current_form() in WWW::M +echanize context my $input = $form->find_input("file_name"); $input->headers(content_type => "application/vnd.ms-excel"); my $req = $form->click(); print $req->as_string();

which would output (with test.csv containing the "foo;bar;..."):

POST http://localhost/ Content-Length: 219 Content-Type: multipart/form-data; boundary=xYzZY --xYzZY Content-Disposition: form-data; name="file_name"; filename="test.csv" Content-Type: application/vnd.ms-excel foo;bar;baz 1;2;3 --xYzZY Content-Disposition: form-data; name="submit" Submit --xYzZY--

(commenting out the $input->headers(...), you'd get the default "Content-Type: text/plain" for test.csv instead...)


In reply to Re: WWW::Mechanize issue by almut
in thread WWW::Mechanize issue by shag

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.