in reply to Re^2: libwww-perl basics
in thread libwww-perl basics

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

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

    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. +..

      OK, then try it like this:

      for my $header ($response->headers->header_field_names) { ... }

      ...roboticus

        That works (thank you), although (somewhat oddly) all of the cookies (multiple headers with the same field name) are run together.
        for my $header ($response->headers->header_field_names) { print $header, ": ", $response->header($header), "\n"; }
        That produces:
        [...] Set-Cookie: cookiea; expires=[time]; path=/; domain=.example.comcookie +b expires=[time]; path=/; domain=.example.comcookiec expires=[time]; +path=/; domain=.example.com; HttpOnly [...]
        I can live with that for now.
Re^4: libwww-perl basics
by rowdog (Curate) on Aug 12, 2010 at 17:41 UTC
    The response has the headers so s/ua/response/g