Hello everyone - long time reader (as google turns up perlmonks quite frequently) first time poster, as I'm frustratingly stuck. The Mechanize perl doc even recommends asking for assistance here, so I'm giving it a shot.

The problem: I'm attempting to use WWW::Mechanize to log into an apc network management card to scrape the temperature data contained in one of the pages. This should be an easy task... I would think.

I started by creating a super simple form on my own to verify I could submit a form with WWW::Mechanize. I quickly got this functional.

Now, with basic functional code, I used mech-dump to get the form information that I would need to submit (and verified this by recording logging into the interface with HTTP Watch). HTTP Watch also shows that after submitting the correct username, password, and language, you recieve a 303 response directing you to a new page that contains your session ID as part of the URI - so I MUST use the data returned by the 303 to get any further into the interface.

mech-dump returned this: login_username= (text) login_password= (password) prefLanguage=00000000 (option) *00000000/English submit=Log On (submit) <NONAME>=<UNDEF> (reset)

Given this information, I modified my (functional) test script to use the data provided by mech-dump and HTTP watch:

#!/usr/bin/perl use WWW::Mechanize; use Crypt::SSLeay; my $mech = WWW::Mechanize->new( autocheck => 0); $url="https://192.168.0.2"; $mech->get( $url ); print $mech->status; $mech->form_name('HashForm1'); $mech->field("login_username",'username'); $mech->field("login_password",'password'); $mech->field("prefLanguage",00000000); $mech->submit_form(); print "form submitted, reponse was ",$mech->status," printing header\n +"; my $response = $mech->response(); for my $key ( $response->header_field_names() ) { print $key, " : ", $response->header( $key ), "\n"; } exit;
The problem at this point is, I always recieve a 500 back from the page. To make matters worse, I've tried to modify this script to submit to several other interfaces (IBM AMM, HP ILOM, etc) and none of them accept the data that I'm submitting, so it appears to be a problem with my perl.

Any help would be GREATLY appreciated, even if its just links to some extra documentation that I can read to find my own way (I've already tried the perdoc and the cookbook here: http://search.cpan.org/dist/WWW-Mechanize/lib/WWW/Mechanize/Cookbook.pod)

Thanks!


In reply to Seeking assistance with WWW::Mechanize Form Submission by tspang

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.