Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Debugging Mech,LWP...
Here is a good way to debug request->responses that are going between LWP and the web server.
use Aspect; my $pcut = call qr/LWP::UserAgent::send_request/; before { my $ctx = shift; print "req================\n"; print $ctx->params->[1]->as_string; } $pcut; after { my $ctx = shift; print "resp----------------\n"; print $ctx->return_value->headers->as_string; print "==================\n"; } $pcut; use WWW::Mechanize; my $m = WWW::Mechanize->new; $m->get("http://www.google.com");

req================ GET http://www.google.com Accept-Encoding: identity User-Agent: WWW-Mechanize/1.14 resp---------------- Cache-Control: private Date: Wed, 16 May 2007 17:08:09 GMT Server: GWS/2.1 Content-Length: 3971 Content-Type: text/html; charset=ISO-8859-1 Content-Type: text/html; charset=ISO-8859-1 Client-Date: Wed, 16 May 2007 17:10:46 GMT Client-Peer: x.x.x.x:80 Client-Response-Num: 1 Set-Cookie: PREF=ID=f76dcf3c38b51e16:TM=1179335289:LM=1179335289:S=WLL +o_3xLrawI8ife; expires=Sun, 17-Jan-2038 19:14:07 GMT; path=/; domain= +.google.com Title: Google ==================
You can use $c->return_value->as_string, if u want to get the content of the response too. And of course you need to install Aspect.pm module ;)

In reply to Debugging LWP and family by rootcho

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-04-24 12:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found