HTTP::Cookies save() not Saving Temporary Cookies

This section provides a tutorial example showing that the save() method in the HTTP::Cookies class does not save any temporary (non-persistent) cookies to the cookie jar file.

In the previous tutorial, we have tested LWP-UserAgent-Request.pl on persistent cookies, which are correctly saved into the "HTTP-Cookies.jar" file.

Now let's see how LWP-UserAgent-Request.pl behaves on temporary (non-persistent) cookies. To do this test, we my CGI script CGI-pm-Manage-Cookies.pl running on my local Apache Web server as described in previous tutorials.

C:\herong>LWP-UserAgent-Request.pl 
   GET http://localhost/CGI-pm-Manage-Cookies.pl

GET http://localhost/CGI-pm-Manage-Cookies.pl
User-Agent: Mozilla/5.0 (Windows NT 6.1)

HTTP/1.1 200 OK
Connection: close
Server: Apache/2.2.25 (Win32)
Content-Type: text/html; charset=ISO-8859-1
Client-Transfer-Encoding: chunked
Set-Cookie: Chocolate_1=Another%20chocolate%20cookie%20for%20you%2...
Set-Cookie: Sugar_2=Another%20sugar%20cookie%20for%20you%21; path=/
Title: CGI-pm-Manage-Cookies.pl

<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang=...
<head>
<title>CGI-pm-Manage-Cookies.pl</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8...
</head>
<body>
<pre>0 Cookies received from request:
</pre>
</body>
</html>


C:\herong>type HTTP-Cookies.jar

#LWP-Cookies-1.0
Set-Cookie3: datr=df0dU_W0r6vNIWj_NgpYQMJ7; path="/"; domain=.face...
Set-Cookie3: fr=0oswe6EQT4vYQsVEs.AWXgFm5hU3wMtefwkipG9OoNw3A.BTEl...
Set-Cookie3: lu=SgFEbQxflkf9cYQqNmEjSYmw; path="/"; domain=.facebo...
Set-Cookie3: NID="67=v4hLLg1a_TYSA0jgDZmyiEFmp2r3qWujpGhCRAx9by8hS...
Set-Cookie3: PREF="ID=39f3c35845eeda94:U=5282f19f1a13190a:FF=0:TM=...

Based on the output of the first command, 2 cookies "Chocolate_1" and "Sugar_2" were received by the client script.

But based on the output of the second command, these 2 cookies were not saved to the "HTTP-Cookies.jar".

This indicates that the save() method in the HTTP::Cookies class does not save any temporary cookies to the cookie jar file.

If save() method is not saving temporary cookie to the cookie jar file, we will not be able to use the LWP-UserAgent-Request.pl script to send multiple requests that shares temporary cookies.

See the next tutorial on to how enhance the LWP-UserAgent-Request.pl script.

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

 References

 PDF Printing Version