What Is HTTP::Request?
This section describes what is HTTP::Response - a Perl class that represents the HTTP request message to be sent to a Web server.
If you are only using get() and post() methods, then you don't need to know the HTTP::Request class and objects.
The get() or post() method will automatically create the HTTP::Request object for you.
But if you want to create your own special HTTP request, you need to learn the HTTP::Request class.
What Is HTTP::Request?
HTTP::Request, developed by Gisle Aas, is a Perl class that represents the HTTP request message to be sent
to a Web server. An HTTP response consists of a request line, some headers, and a content body.
The current version of HTTP::Response is 6.00, which supports the following properties and methods:
- new() - Construct a new HTTP::Request object with given request method, server URI,
headers, and content body.
- parse() - Construct a new request object by parsing the given raw HTTP request string
- method() - Get/set the method attribute, which represent the HTTP request method "GET", "HEAD", "PUT" or "POST".
- uri() - Get/set the uri attribute, which consists of the protocol name "HTTP", the web server host name and port,
the path of the resource location on the server and other parameters.
- header() - Get/set header values of the HTTP request message.
- content() - Get/set the raw content of the HTTP response message.
- as_string() - Return a textual representation of the entire response.
Again, let's use the Perl command line to do a simple test:
C:\herong>perl -e "use LWP::UserAgent;
It worked!. The HTTP::Request object created by the LWP::UserAgent class was so simple and short.
Here is how the code works:
- "use LWP::UserAgent;" statement imports the LWP::UserAgent class into the execution environment.
- "(new LWP::UserAgent())" expression creates a LWP::UserAgent object with default settings.
- "...->get('http://herongyang.com')" expression asks the the LWP::UserAgent object to create
an HTTP::Request object with "GET" as the request method, and "http://herongyang.com" as the request URI.
Then the HTTP::Request object is sent to the Web server for processing.
Then an HTTP::Response object is created using the returning HTTP response message from the Web server.
- "...->request()" expression returns the HTTP::Request object referenced by the HTTP::Response object.
- "...->as_string()" expression dumps the HTTP::Request object as a string.
Last update: 2014.
Table of Contents
About This Book
Perl on Linux Systems
ActivePerl on Windows Systems
Data Types: Values and Variables
Expressions, Operations and Simple Statements
User Defined Subroutines
Perl Built-in Debugger
Name Spaces and Perl Module Files
Symbolic (or Soft) References
Hard References - Addresses of Memory Objects
Objects (or References) and Classes (or Packages)
Typeglob and Importing Identifiers from Other Packages
String Built-in Functions and Performance
File Handles and Data Input/Output
Open Files in Binary Mode
Open Directories and Read File Names
File System Functions and Operations
Converting Perl Script to Executable Binary
Using DBM Database Files
Using MySQL Database Server
Socket Communication Over the Internet
XML::Simple Module - XML Parser and Generator
XML Communication Model
SOAP::Lite - SOAP Server-Client Communication Module
Perl Programs as IIS Server CGI Scripts
CGI (Common Gateway Interface)
XML-RPC - Remote Procedure Call with XML and HTTP
RPC::XML - Perl Implementation of XML-RPC
Integrating Perl with Apache Web Server
CGI.pm Module for Building Web Pages
►LWP::UserAgent and Web Site Testing
What Is LWP::UserAgent?
What Is HTTP::Response?
►What Is HTTP::Request?
LWP-UserAgent-GET.pl - Sending a GET Request
LWP-UserAgent-GET-Redirect.pl - Following HTTP Redirects
http-equiv="Refresh" Meta Tag not Followed
LWP-UserAgent-POST.pl - Posting Form Data
post() Method not Following Redirect Location
LWP-UserAgent-POST-Redirect.pl - Posting with Redirects
What Is HTTP::Cookies?
LWP-UserAgent-Request.pl - GET, POST and Cookies
LWP-UserAgent-Request.pl - Login to facebook.com
HTTP::Cookies save() not Saving Temporary Cookies
LWP-UserAgent-Request-Cookies.pl - Sending Request with Cookies
PDF Printing Version