in reply to libwww-perl basics

In answer to your second question: You didn't read HTTP::Response very carefully, or you would have noticed the note to refer to the documentation on HTTP::Headers for more information. That document clearly describes:

$h->header_field_names Returns the list of distinct names for the fields present in the header. The field names have case as suggested by HTTP spec, and the names are returned in the recommended "Good Practice" order.

...roboticus

Replies are listed 'Best First'.
Re^2: libwww-perl basics
by Anonymous Monk on Aug 12, 2010 at 13:02 UTC

    Actually, I did see that, but I thought (I really don't understand this at all) that I would have to make a second request to get just the headers.

    Can I get those after $response = $ua->get..., and if so, how?

      The docs for HTTP::Response don't give a method to access the HTTP::Headers object, but it mentions that it's a subclass of HTTP::Message. So we have to take a look at the documentation for HTTP::Message, and there we see that it provides the headers method to give you a reference to the HTTP::Headers object. So assuming $ua is an HTTP::Response object, you'd do something like this:

      for my $header (@{$ua->headers->header_field_names}) { print $header, ": ", $ua->header($header), "\n"; }

      Note: I don't write web apps, so I've never used the HTTP classes, so this is (of course!) untested. But hopefully it will lead you in the right direction.

      ...roboticus

        I tried that, and I get:

        Can't locate object method "headers" via package "LWP::UserAgent" at.. +.

        I also tried:

        for my $header (@{$response->headers->header_field_names}) { print $header, ": ", $response->header($header), "\n"; }
        and I got:
        Can't use string ("29") as an ARRAY ref while "strict refs" in use at. +..
        The response has the headers so s/ua/response/g