compare what FireFox gives you against what WWW::Mechanize or LWP::UserAgent give you.

I usually use HTTP::Proxy to do that comparison. Then I not only see what firefox sent, but what the Data::Dumper dump of the LWP object looks like.

The output in the query log shouldn't be used directly, but the sources it logs will prove the query can be done with LWP. The next step is just to figure out what the object you built by hand is missing.

use strict; use HTTP::Proxy qw(:log); my $proxy = new HTTP::Proxy( host => "localhost", port => 9999, logmask => HEADERS | STATUS, agent => new myagent, ); unlink "querylog.pl" if -f "querylog.pl"; $proxy->start; package myagent; use strict; use base 'LWP::UserAgent'; use Data::Dumper; local $Data::Dumper::Indent = 1; sub new { my $class = shift; my $this = $class->SUPER::new(@_); $this->timeout( 20 ); $this->agent("SniffProxy/0.9"); $this->requests_redirectable([qw(GET POST)]); return $this; } sub simple_request { my $this = shift; my ($req) = @_; if( $req->isa("HTTP::Request") ) { # and $req->method eq "POST" ) +{ open my $out, ">>", "querylog.pl" or die "couldn't open query + log: $!"; print $out "#############################\n# $req->{_method} $ +req->{_uri}\n# HTTP::Request {", "{{\n"; print $out "use strict;\n"; print $out "use URI::http;\n"; print $out "use HTTP::Request;\n"; print $out "use LWP::UserAgent;\n"; print $out "use HTTP::Request::Common qw(POST GET);\n\n"; print $out "my ", Dumper( $_[0] ); print $out "# }}", "}\n\n"; print $out "my \$ua = new LWP::UserAgent;\n"; print $out " \$ua->timeout( 10 );\n"; print $out " \$ua->requests_redirectable([qw(GET POST)]);\n" +; print $out "\n"; print $out "\$ua->simple_request( \$VAR1, \"content.dat\" );\n +"; close $out; } return $this->SUPER::simple_request(@_); }

-Paul


In reply to Re^2: LWP::UserAgent can't login to phpbb forum by jettero
in thread LWP::UserAgent can't login to phpbb forum by mnem0

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.