In this activity we use a Java program to send an HTTP request to a web server.
In addition to the Solution document, the project for this exercise contains two classes, which are complete:
You are to use the RequestSender class to connect to the home page of the Open University website and display its HTML source.
Open Main and study the code. You will see that it creates an instance of RequestSender and then invokes its run method. The run method takes three arguments. The first is the symbolic address at which the server is located. The second is the port number it will be listening on. The third argument is the request the client (our program) will send to the server, which in this case is:
"GET / HTTP/1.0" + "\r\n\r\n"
This asks for everything from the home level page at the site, using HTTP version 1.0. The extra characters are part of the protocol the server will expect. The class is programmed using sockets, which will be discussed later in this unit. You are not expected to follow the details at this point.
You will need to be connected to the internet. Compile and run the project, observing the result. You should see the HTML for the Open University home page. In fact, the result will be largely the same as when we connected to this home page in Activity 9.1!
Can you spot anything different about the output this time?