However, this browser should not only
display the image, it should also, in a small window above the image,
display all
HTTP headers
received from the server serving the image.
For instance, an HTTP request for
http://www.google.com/intl/en_ALL/images/logo.gif,
results in the following response headers being returned by google's
Web server:
HTTP/1.0 200
OK
Content-Type:
image/gif
Last-Modified:
Wed, 07 Jun 2006 19:38:24 GMT
Expires: Sun,
17 Jan 2038 19:14:07 GMT
Server:
GWS/2.1
Content-Length:
8558
Date: Thu, 15
Mar 2007 23:31:27 GMT
Connection:
Keep-Alive
Length: 8558
(8.4K) [image/gif]
In addition, we want to separate the
HTTP response status from
the headers and display it in a separate
Status code
window (see example above).
Clearly, since we do not know how many headers we will be receiving
from the server, we must make the window that lists the returned
headers scrollable.
Similarly, we want to accommodate for large images. Hence, we want some
way of scaling the images.
Your program should also recognize whether or not an image was
requested. If not, an error message should signify the error.
Finally, make sure that you build in a facility for handling timeouts;
i.e., handling an HTTP server
that does not reply timely.
Click here for a demo version of the program.
Some tips and hints:
- To form the URI (URL), you might want to use the System.Uri
class.
- To make the HTTP request (using the Uri class),
you
might want to use the System.Net.HttpWebRequest
class.
- To get a hold of the HTTP response headers and body, you might
want to use the System.Net.HttpWebResponse
class.
- These classes are very rich and powerful. For instance, almost
anything you want to know about the HTTP response (its status, is it an
image? how many bytes does it have?, what are its headers? etc.) is stored on the HttpWebResponse.
- A simple way to accommodate large images is to set the SizeMode of
the PictureBox
to StrechtchImage
and to allow the window as a whole to be stretched in both vertical and
horizontal directions. However, keep in mind that when you allow the
whole window to be stretched, you must accommodate stretching of its
parts; e.g., the various text
boxes as well.
- An HTTP timout (in milliseconds) can be set by using the timout
attribute of the HttpWebRequest.??
attribute.Experiment with this setting it to 5,000 and 10,000
milliseconds. Especially in the BXL112A lab you might notice some
interesting differences.