Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

WWW::Mechanize POST Method

by rgatliff (Sexton)
on Dec 29, 2004 at 17:07 UTC ( #418023=perlquestion: print w/replies, xml ) Need Help??

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 (proxy.pl) 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.


    Dave

      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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://418023]
Approved by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2023-01-27 03:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?