HTTP::Response - Class encapsulating HTTP Responses
require HTTP::Response;
The HTTP::Response class encapsulate HTTP style responses. A response consist of a response line, some headers, and a (potential empty) content. Note that the LWP library will use HTTP style responses also for non-HTTP protocol schemes.
HTTP::Response
Instances of this class are usually created and returned by the request() method of an LWP::UserAgent object:
request()
LWP::UserAgent
... $response = $ua->request($request) if ($response->is_success) { print $response->content; } else { print $response->error_as_HTML; }
HTTP::Response is a subclass of HTTP::Message and therefore inherits its methods. The inherited methods are header(), push_header(), remove_header(), headers_as_string(), and content(). The header convenience methods are also available. See HTTP::Message for details.
HTTP::Message
Constructs a new HTTP::Response object describing a response with response code $rc and optional message $msg
$rc
$msg
These methods provide public access to the member variables. The first two containing respectively the response code and the message of the response.
The request attribute is a reference the request that gave this response. It does not have to be the same request as passed to the $ua->request() method, because there might have been redirects and authorization retries in between.
The previous attribute is used to link together chains of responses. You get chains of responses if the first response is redirect or unauthorized.
Returns the base URL for this response. The base URL can come from 3 sources:
Embedded in the document content, for instance <BASE HREF="..."> in HTML documents.
A "Base:" header in the response
The URL used to request this response
A base URL embedded in the document will initialize the "Base:" header in the response object, which means that only the last 2 sources are checked by this method.
Method returning a textual representation of the request. Mainly useful for debugging purposes. It takes no arguments.
These methods indicate if the response was informational, sucessful, a redirection, or an error.
Return a string containing a complete HTML document indicating what error occurred. This method should only be called when $r->is_error is TRUE.
To install LWP, copy and paste the appropriate command in to your terminal.
cpanm
cpanm LWP
CPAN shell
perl -MCPAN -e shell install LWP
For more information on module installation, please visit the detailed CPAN module installation guide.