Skip to content

Instantly share code, notes, and snippets.

@ozuma
Created May 9, 2013 13:59
Show Gist options
  • Save ozuma/5547591 to your computer and use it in GitHub Desktop.
Save ozuma/5547591 to your computer and use it in GitHub Desktop.
GET HTTP Response Headers as Array.
#!/usr/bin/perl
use strict;
use warnings;
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
$ua->agent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:20.0) Gecko/20100101 Firefox/20.0");
my $req = HTTP::Request->new(GET => 'http://www.example.com/');
my $res = $ua->simple_request($req);
my @header_names = $res->headers->header_field_names;
foreach my $header_name (@header_names) {
print $header_name . ": " . $res->headers->header($header_name) . "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment