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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Subclass from LWP::UserAgent and implement the method progress. Then I think you can do pretty much whatever you want. The following snippet only prints out available response header names, but you can extend it to also print the header values, and for request headers as well.
$ cat lwp-headers.pl #!/usr/bin/perl package MyLWP; use base 'LWP::UserAgent'; sub progress { my($self, $status, $resp) = @_; if ($resp) { my @headers = $resp->header_field_names; print "response headers: @headers\n"; } } package main; my $ua = MyLWP->new; my $url = shift || 'http://gmail.google.com'; my $rp = $ua->get($url); print $rp->status_line, "\n"; $ ./lwp-headers.pl http://www.google.com response headers: Cache-Control Connection Date Location Content-Lengt +h Content-Type Client-Peer Client-Response-Num Set-Cookie Title X-Cac +he X-Cache-Lookup response headers: Cache-Control Connection Date Location Content-Lengt +h Content-Type Client-Date Client-Peer Client-Response-Num Set-Cookie + Title X-Cache X-Cache-Lookup response headers: Cache-Control Connection Date Content-Type Client-Pe +er Client-Response-Num Set-Cookie Title X-Cache X-Cache-Lookup response headers: Cache-Control Connection Date Content-Type Client-Pe +er Client-Response-Num Set-Cookie Title X-Cache X-Cache-Lookup response headers: Cache-Control Connection Date Content-Type Client-Pe +er Client-Response-Num Set-Cookie Title X-Cache X-Cache-Lookup response headers: Cache-Control Connection Date Content-Type Client-Pe +er Client-Response-Num Set-Cookie Title X-Cache X-Cache-Lookup response headers: Cache-Control Connection Date Content-Type Client-Pe +er Client-Response-Num Set-Cookie Title X-Cache X-Cache-Lookup response headers: Cache-Control Connection Date Content-Type Client-Pe +er Client-Response-Num Set-Cookie Title X-Cache X-Cache-Lookup response headers: Cache-Control Connection Date Content-Type Client-Da +te Client-Peer Client-Response-Num Set-Cookie Title X-Cache X-Cache-L +ookup 200 OK $ ./lwp-headers.pl response headers: Cache-Control Connection Date Pragma Location Conten +t-Type Client-Peer Client-Response-Num Title X-Cache X-Cache-Lookup response headers: Cache-Control Connection Date Pragma Location Conten +t-Type Client-Date Client-Peer Client-Response-Num Title X-Cache X-Ca +che-Lookup response headers: Cache-Control Connection Date Pragma Location Conten +t-Type Client-Peer Client-Response-Num Set-Cookie Title X-Cache X-Cac +he-Lookup response headers: Cache-Control Connection Date Pragma Location Conten +t-Type Client-Date Client-Peer Client-Response-Num Set-Cookie Title X +-Cache X-Cache-Lookup response headers: Cache-Control Connection Date Pragma Location Conten +t-Type Client-Peer Client-Response-Num Set-Cookie Title X-Cache X-Cac +he-Lookup response headers: Cache-Control Connection Date Pragma Location Conten +t-Type Client-Peer Client-Response-Num Set-Cookie Title X-Cache X-Cac +he-Lookup response headers: Cache-Control Connection Date Pragma Location Conten +t-Type Client-Date Client-Peer Client-Response-Num Set-Cookie Title X +-Cache X-Cache-Lookup response headers: Cache-Control Connection Date Pragma Server Content- +Length Content-Type Client-Peer Client-Response-Num Client-SSL-Cert-I +ssuer Client-SSL-Cert-Subject Client-SSL-Cipher Client-SSL-Warning Se +t-Cookie ..... response headers: Cache-Control Connection Date Pragma Server Content- +Length Content-Type Client-Date Client-Peer Client-Response-Num Clien +t-SSL-Cert-Issuer Client-SSL-Cert-Subject Client-SSL-Cipher Client-SS +L-Warning Set-Cookie Title 200 OK

Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!


In reply to Re: Getting all Headers by naikonta
in thread Getting all Headers by Yappo

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 meditating upon the Monastery: (6)
As of 2024-03-28 08:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found