Retrieving Query Parameters and Headers

This section provides a tutorial example on how to retrieve input parameters from query string and request content, and retrieve request headers.

Next, let's play with those methods that retrieve input parameters from query string including request content, and request headers. Here is a simple example Perl CGI script:

#- Copyright (c) All Rights Reserved.

   use CGI;
   $query = CGI->new();

   $text = "";

#- Getting the request method
   $text .= "Request method = ".$query->request_method()."\n";

#- Getting input data from the query string and from the data content
   $text .= "Names and values from param():\n";
   @names = $query->param();
   foreach $name (@names) {
      $text .= "   $name = ".$query->param($name)."\n";

#- Getting request headers
   $text .= "Names and values from http():\n";
   @names = $query->http();
   foreach $name (@names) {
      $text .= "   $name = ".$query->http($name)."\n";

   print $query->header();
   print $query->start_html(-title=>'');
   print $query->pre($text);
   print $query->end_html();

Copy to C:\local\apache\htdocs and browse to: http://localhost/

You should see the following result in the browser. The result looks good.

Request method = GET
Names and values from param():
   name = joe
   age = 21
   student =
Names and values from https():
   HTTP_ACCEPT_ENCODING = gzip, deflate
   HTTP_CONNECTION = keep-alive
   HTTP_ACCEPT = text/html,application/xhtml+xml,application/xml;q...
   HTTP_HOST = localhost
   HTTP_DNT = 1
   HTTP_ACCEPT_LANGUAGE = en-US,en;q=0.5
   HTTP_USER_AGENT = Mozilla/5.0 (Windows NT 6.1; rv:26.0) Gecko/2...

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

 Image and Picture Processing

 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 Module for Building Web Pages

 What Is

 Generating HTML Document with

Retrieving Query Parameters and Headers

 Retrieving Environment and Script Information

 Redirecting Browser to a URI

 "Refresh" http-equiv Meta Tag

 What Is CGI::Cookie?

 Retrieving and Setting HTTP Cookies

 LWP::UserAgent and Web Site Testing

 Converting Perl Script to Executable Binary

 Managing Perl Engine and Modules on macOS

 Archived Tutorials


 Full Version in PDF/EPUB