Arroze has asked for the wisdom of the Perl Monks concerning the following question:

I've browes/searched the discussions on this site and didn't see an answer or help to my question, so here it is:

Question: How would I use LWP (or similar lib/mod) to get HTTP headers? (not just the HTML code after the 'Content-type' in the header)

I have a script that will sucessfully get HTML code from a remote web server, that's not a problem at all. I've been reading all over the place and even looking at the LWP source to no avail. The reason I want to get the headers is because I need to view all the data my web server spews out as a result of a HTTP request. I need to see if a cookie is being passed back to the client, and capture it. If anyone can tell me that I'm going about this all wrong and why, or that there's a simple mehod of getting an entire HTTP response (not just the HTML code after the 'Content-type') that'd be great!

Replies are listed 'Best First'.
Re: Obtaining HTTP Headers using LWP
by Fastolfe (Vicar) on Feb 07, 2001 at 05:10 UTC
    I'm making a couple of dangerous assumptions: Assumption 1: You are using LWP::UserAgent and not LWP::Simple. Following from that assumption, I must assume (based upon your message) that you know how to use LWP::UserAgent to perform an HTTP::Request on a given URL, and are able to use HTTP::Response returned from your request to get your data. From here it gets pretty easy:
    print $response->headers_as_string;
    This is documented in HTTP::Response. I'd also take a glance at HTTP::Headers.
Re: Obtaining HTTP Headers using LWP
by Arroze (Initiate) on Feb 07, 2001 at 05:14 UTC
    Yes, you were correct in making those assumptions Fastolfe, and that snipplet of code was just the thing I was looking for. Thanks a bunch!