Write a client program which invokes Form.cgi with GET method specified, using either the stream socket API or the URL class.

Hand in the program listings.

Below is the data that needs to be exchanged between the client and the server:
```
>telnet www 80
Trying 129.65.241.7...
Connected to tiedye-srv.csc.calpoly.edu.
Escape character is '^]'.
GET /~mliu/form/getForm.cgi?name=Donald HTTP/1.0

HTTP/1.1 200 OK
Date: Sun, 24 Feb 2002 22:30:55 GMT
Server: Apache/1.3.9 (Unix) ApacheJServ/1.0
Connection: close
Content-Type: text/html

This page is generated dynamically by getForm.cgi. h2>

Query Results

You submitted the following name/value pairs:



  • name = Donald
    Connection closed by foreign host.
    ```


    Below is the data that needs to be exchanged between the client and the server:
    The idea is for the client program to generate a request header same as the line (followed with a ) keyed in above to obtain the response from the server via the web script getForm.cgi.
    Using the socket API, the HTTPClient.java file is modified as follows

    ```
    //HTTPClient.java
    try {
    InetAddress host =
    InetAddress.getByName("www.csc.calpoly.edu");
    int port = 80;
    String fileName =
    "/~mliu/form/getForm.cgi?name=Donald";
    String request =
    "GET " + fileName + " HTTP/1.0\n\n";
    MyStreamSocket mySocket =
    new MyStreamSocket(host, port);
    /**/ System.out.println("Connection made");
    mySocket.sendMessage(request);
    // now receive the response from the HTTP server
    String response;
    response = mySocket.receiveMessage();
    // read and display one line at a time
    while (response != null) {
    System.out.println(response);
    response = mySocket.receiveMessage();
    }
    ```

    ```
    // URLBrowser
    try {
    String host = "www.csc.calpoly.edu";
    String port = "80";
    String fileName = "~mliu/form/getForm.cgi?"
    +"name=Donald%20Duck&quest=gold%20medal";

    String HTTPString =
    "http://"+host+":"+port+"/"+fileName;
    URL theURL = new URL(HTTPString);

    InputStream inStream = theURL.openStream( );
    BufferedReader input =
    new BufferedReader
    (new InputStreamReader(inStream));
    String response;
    response = input.readLine();
    // read and display one line at a time
    while (response != null) {
    System.out.println(response);
    response = input.readLine();
    } //end while
    }
    ```

    Computer Science & Information Technology

You might also like to view...

A spreadsheet can examine several alternative ____scenarios.

A. average B. what-if C. test case D. how-to

Computer Science & Information Technology

What is the time complexity of the Floyd-Warshall algorithm?

a. O(V^3) b. O(V^2) c. O(E*V) d. O(E*E)

Computer Science & Information Technology

You would use a(n) ________ query to make changes to the retail price field for records meeting a specified criteria

A) make table B) append C) update D) select

Computer Science & Information Technology

The term ____ refers to any computer component that is required to perform work.

A. resource B. hardware C. software D. device

Computer Science & Information Technology