It isn't readily apparent from the docs how to get at the HTTP headers while using WWW::Mechanize. The miscellaneous add_header and delete_header likely don't do what you want. The following snippet gets you a complete list of headers and their values as well as shows you how to get a specific value if you know the header key in advance.
#!/usr/bin/perl use strict; use warnings; use WWW::Mechanize; my $mech = WWW::Mechanize->new( autocheck => 1 ); $mech->get( 'http://www.perlmonks.org/' ); my $response = $mech->response(); for my $key ( $response->header_field_names() ) { print $key, " : ", $response->header( $key ), "\n"; } # Or if you know the header key in advance my $header = $mech->response()->header( 'key' );
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: HTTP Headers Using WWW::Mechanize
by holli (Abbot) on Jan 31, 2005 at 18:26 UTC | |
by Limbic~Region (Chancellor) on Jan 31, 2005 at 18:31 UTC | |
Re: HTTP Headers Using WWW::Mechanize
by merlyn (Sage) on Jan 31, 2005 at 19:48 UTC | |
by Limbic~Region (Chancellor) on Jan 31, 2005 at 20:08 UTC | |
by petdance (Parson) on Jan 31, 2005 at 21:36 UTC | |
by Limbic~Region (Chancellor) on Feb 01, 2005 at 14:19 UTC | |
by igoryonya (Pilgrim) on Oct 15, 2022 at 01:11 UTC | |
by marto (Cardinal) on Oct 15, 2022 at 13:34 UTC | |
|
Back to
Cool Uses for Perl