BA372 - Assignment 1: HTTP Image Browser
In VC#.Net, write a simple HTTP image browser; i.e., a Windows forms app which, like an
ordinary Web browser, allows users to enter a URL in a textbox at the
top of the window, makes an HTTP request for the resource located at the URL
and which, if the URL references an image file; e.g., *.jpg, *.gif, *.png, etc., displays the retrieved image in the
However, this browser should not only
display the image, it should also, in a small window above the image,
display the HTTP response line and all HTTP headers
received from the server serving the HTTP request. For instance, an HTTP
request for http://www.google.com/intl/en_ALL/images/logo.gif,
results in the following response line and headers being returned by Google's
At this point in our coursework, we should also start thinking a little about user interface issues.
For instance, just like users can enlarge or shrink their Web browser window, so should your user be able to
enlarge and shrink the window of your HTTP image browser. Obviously, with such enlarging/shrinking, the
interface elements contained in the window should enlarge/shrink accordingly.
Your program should also recognize whether or not an image was
requested and if the request actually succeeded. If not, an error message should gracefully handle the error.
Similarly, your program should recognize if a user entered an invalid URL.
Also, make sure that you build in a facility for handling timeouts;
i.e., handling an HTTP server
that does not reply within a certain amount of time.
Finally, make it so that, just as in a regular browser, you can hit the Enter/Return key on the keyboard instead of having to click the
Some tips and hints:
HTTP/1.1 200 OK
Date: Fri, 11 Mar 2016 23:22:45 GMT
Expires: Fri, 11 Mar 2016 23:22:45 GMT
Cache-Control: private, max-age=31536000
Last-Modified: Mon, 02 Apr 2012 02:13:37 GMT
X-XSS-Protection: 1; mode=block
Length: 8558 (8.4K) [image/gif]
In addition, we want to distinguish the HTTP response status from
the headers and display it in a separate Status code
textbox (see example above).
Clearly, since we do not know how many headers we will be receiving
from the server, we must make the box that lists the returned
headers scrollable. Similarly, we want to accommodate for large images. Hence, we want some
way of scaling the images or be able to scroll them.
- You instructor is very aware of the fact that you have not practiced HTTP requests in a lab. However, at this point in
your training you should be able to 'make Google your friend' and be able to formulate Google queries which are both targeted and precise enough
to give you few but very good search results. For instance, in the next tip/hint, you'll be advised to use the
System.Net.HttpWebRequest class for
forming a C# HTTP request. You might ask Google for a simple or basic example on how to use that
class: e.g., c# HttpWebRequest "simple example" (the double quotes are important!!)
- 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, you might want to use the System.Net.HttpWebResponse class.
- These HttpWebRequest and HttpWebResponse 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.
- Whenever we have to display images, we have a potential scaling problem; the image is
either larger or smaller than the canvas on which we want to display it. Although several ways
to deal with the problem exist, a simple (quick and dirty) way to accommodate large images
is to embed the PictureBox on which we display the image inside a
Panel object and let the
scroll the PictureBox. If we make the
PictureBox object larger than the
Panel object, set its
Autosize and set the
Autoscroll property to
Panel will scroll the