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

In LWP, what is the difference between returning a request via $req->content and $req->as_string, where $req is the request variable?

Replies are listed 'Best First'.
Re: LWP $req-content vs $req-as_string
by Fastolfe (Vicar) on Jan 15, 2001 at 19:38 UTC
    From the HTTP::Response and HTTP::Message (from which HTTP::Response is descended) documentation:
    $r->as_string Returns a textual representation of the response. Mainly useful for debugging purposes. It takes no arguments. $mess->content([$content]) The content() method sets the content if an argument is given. If no argument is given the content is not touched. In either case the previous content is returned.
    Have you tried both and noted what their results are? I suspect content returns the content of the response, while as_string returns a string representation of the response object as a whole, which likely includes things like HTTP status information and headers. Since most HTTP objects are based upon a textual HTTP message of some kind, you will typically find that they usually support an "as_string" method to un-do that parsing, giving you what should ordinarily be the same textual HTTP response that was given in the first place.
Re: LWP $req-content vs $req-as_string
by merlyn (Sage) on Jan 15, 2001 at 19:35 UTC