Laboratory Week 4
Learning Objective:
- Implement a simple web client that retrieves web resources (like HTML pages) and display the content of resource on the command line.
- Learn the classes and the methods available in Perl's LWP to complete Assignment 1 part III.
- (Optional) Use Apache's mod_status to view your web server's performance, to supplement what you have already learnt in week 3's laboratory session.
Required Reading:
Week 3 lecture 2
Unit Reader section Three: Web Clients pages 247-260.
Week 3 lecture 1 - section on Apache's mod_status.Access to Software:
The following exercises may be done on your local machine with ActivePerl installed, or on
red.murdoch.edu.au. Instructions on how to access both were given in the week 2 and week 3 labs.If you choose to use your local machine, you will require Perl's LWP library installed on it. The standard installation of ActivePerl should install LWP as well. If it isn't, when you start the exercises below, you will get error messages that look like the following:
C:\> perl get_url.pl
Can't locate LWP.pm in @INC (@INC contains: C:/Perl/lib C:/Perl/site/lib .) at get_url.pl line 5.
BEGIN failed--compilation aborted at get_url.pl line 5.If you get that message in the exercises below, then install the LWP manually by typing the command below:
C:\> perl -MCPAN -e 'install BUNDLE::LWP'
Your machine must be connected to the Internet to execute the above command. It will use FTP to download the relevant files from an FTP server, and then install the library automatically.
LWP is already installed on
red.murdoch.edu.au, so you do not need to do anything if you choose to use red for this work rather than use the local machine. Just begin a telnet or ssh session to red. You will need to use an editor like pico to edit the scripts.Exercises:
Copy the script get_url-pl.txt from examples directory. Rename it to get_url.pl. Understand how it works, and execute it on the command line with a few example URLs:
perl get_url.pl http://www.murdoch.edu.au
perl get_url.pl http://www.it.murdoch.edu.au
What did the script produce?
Hint: You can add "| more" to the end of the above commands if the results scrolls by too fast for you to view. Eg.
perl get_url.pl http://www.murdoch.edu.au | more- Start your Apache web server on red. Do the same as in (1) but using URLs for your web server. What did the script produce?
- Copy the get_url.pl script to another file called get_url_more.pl. Modify the get_url_more.pl script so that instead of just printing out the contents of the retrieved URL, it also prints out the value of the header field "Content-type". You will need to know which LWP method to use for this.
- Here are two CGI scripts on the B336 web site:
http://www.it.murdoch.edu.au/units/b336/labs/examples/send-response1.cgi
http://www.it.murdoch.edu.au/units/b336/labs/examples/send-response2.cgi
Using get_url_more.pl to access them. What did your scripts produce?
Here is the code for the scripts: send-response1.cgi and send-response2.cgi. Understand how the scripts' code and your output relate to each other.
Use a standard web browser to access the two scripts. What does the web browser do when it receives the information from the scripts?
Here is another CGI script:
http://www.it.murdoch.edu.au/units/b336/labs/examples/send-response3.cgi
Here is the code for the script: send-response3.cgi. Use your get_url_more.pl script to access this URL. What did your script do? Why did it do that as oppose to displaying what send-response3.cgi sent it?Extend the basic get_url_more.pl as you wish. Try using the methods in HTTP::Response and HTTP::Request as described in the lectures and Unit Reader.
- You now should have sufficient guidance to complete Assignment 1 part III. Start on the work.
Optional Exercises:
Enable mod_status on your Apache web server (refer to week 3 lecture 1). Compare the information presented with the information available from the performance monitoring commands from week 3's lab.
Look at the web server stress test script as given on page 27 in week 3 lecture 2. Understand how it works. Implement the script, and test it on your web server. Use the performance monitoring tools to look at how your system is performing
Document author: H.L.
Hiew, Unit Coordinator
Last Modified: Monday, 12-Mar-2001 01:58:59 MST
Disclaimer & Copyright Notice © 2001 Murdoch
University