It works in Firefox, why not in $mech? (aka WWW::Mechanize::Debug) [resend]

Peter Stevens <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.lwp
Message-ID <[email protected]>
Hi everyone,

[Someone just asked me about this, and it looks like the attachment got eaten,
in any case I couldn't find it in an online archive of libwww, so here it is
again in-line.

I have found the attached module to be useful when debugging.
This tells you (I think) what $mech is sending to the server on a click()
operation without needing to resort to tcpdump.

In your code, you'll need

use WWW::Mechanize::Debug;

my $mech = WWW::Mechanize::Debug->new(...)

# when you're ready to $mech->click();

print "Request is" . $mech->simulated_click();

Compare this output from what TamperData or LiveHTTPHeaders shows you
when submitting the same request, and chances are, you've found your
problem :-)

Cheers,

Peter

--
Free Cellphone Monitoring Service
www.MinuteWatcher.com


-------------
package WWW::Mechanize::Debug;

# (c) 2006 Peter Stevens. peter (dot) stevens (at) ch-open (dot) ch
# This module may be disutributed under the same conditions as perl itself.

# Debug routine(s?) for use with WWW::Mechanize
#
use strict;
use warnings FATAL => 'all';
our $VERSION = '0.03';

use base qw( WWW::Mechanize );

sub new {
     my $class = shift;
     my %args = @_;
     my $self = $class->SUPER::new( %args );
     return $self;
}

sub simulated_click {
# invoke this method where you would invoke $mech->click() to find out what will
# be sent to the server. Compare the results with Firefox/TamperData. If the
# requests are the same, the results should be the same.
#
     my $this = shift;
     my @args = @_ ;
     my ( $f, $r, $t);
     $f = $this->current_form();  # or one of its cousins - gives an HTML::Forms object
     $r = $f->click( @args );    # gives HTTP::Request object
     $r = $this->_modify_request( $r );  # v1.12 internal routine.  Compatibility?
     $t = $r->as_string();        # text of the request to compare with Tamper Data results.
     return $t;
}

return 1;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.