Perl Tutorials - Herong's Tutorial Examples - Version 5.32, by Dr. Herong Yang
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