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

Right: I do an LWP request() and get an HTTP::Response, which I'd like to be in plaintext. But, shock horror, it isn't! As I found to my horror when attempting to write a downloaded HTML file to a file, it came out as a hash reference or something similarly terrifying. How can I turn it into plaintext?

Replies are listed 'Best First'.
Re: HTTP::Response(s)
by tomhukins (Curate) on Apr 12, 2001 at 18:18 UTC

    Before posting here, read the documentation for the module(s) you're using. In this case, read up on HTTP::Response.

    You'll see that you can use headers_as_string or content, depending on exactly what you want to achieve.

Re: HTTP::Response(s)
by Asim (Hermit) on Apr 12, 2001 at 18:29 UTC

    use $response->as_string() method (untested code slice):

    $useragent = LWP::UserAgent->new; $request = HTTP::Request->new(GET, $url); $response = $useragent->request($request); $response_text = $response->as_string(); print $response_text;

    Check out the docs on HTTP::Response for more info.

    ----Asim, known to some as Woodrow.

Re: HTTP::Response(s)
by suaveant (Parson) on Apr 12, 2001 at 18:16 UTC
    I seem to recall from my using of LWP long ago, that the text is in the hash somewhere, such as _content or something like that...

    Update ahh $res->content holds it, it looks like ($res being the response object)
                    - Ant