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

Probably a beginners question, but here goes: (Any help would be appreciated) I am using WWW::Mechanize to parse a rather complex HTTP 1.1 site. I have attempted to use LWP to no avail mostly due to the HTTP 1.1 meta refresh tags. After logging into the site and getting the opening pages, the additional POSTS are performed using JavaScript. I have captured the requests ( and know what I have to submit, but am unaware how to do a manual post with WWW::Mechanize. As the site maintains it's session with the original Mechanize object, how do I use this object to manually POST? I realize it inherits the LWP object, but am unaware the syntax to perform a POST command as opposed to a get or form. Thanks in advance.

Replies are listed 'Best First'.
Re: WWW::Mechanize POST Method
by davido (Cardinal) on Dec 29, 2004 at 17:25 UTC

    WWW::Mechanize isa (is a) LWP::UserAgent. That means anything that you can do with LWP::UserAgent, you can do with WWW::Mechanize. That turns out to be convenient. LWP::UserAgent has an $agent->post() method, which can be invoked from your WWW::Mechanize object.


      my $response = $browser->post($url, [ 'value1'=>"2", 'value2'=>"0", ## etc.etc.etc.... ], @ns_headers);
      with the WWW:::Mechanize object worked perfectly. Thanks for the help. Rob
Re: WWW::Mechanize POST Method
by perrin (Chancellor) on Dec 29, 2004 at 18:27 UTC
    If you use HTTP::Recorder to capture the interaction, I believe it will write the POST for you. Ignore the warning in the docs about JavaScript; it's not true.
Re: WWW::Mechanize POST Method
by dba (Monk) on Dec 29, 2004 at 17:25 UTC
    If the page has a button, you can use the $mech->click() method. If you need to POST, you can submit the form using $mech->submit_form( ... ) method.