- Hypertext Transfer Protocol
- The Structure of an HTTP Message
- The Structure of an HTTP Request
- The Structure of an HTTP Response
- Testing an HTTP Connection
- Passing Request Parameters
- Client Page Caching
- URI Redirection and Page Refresh
- Persistent Connections
- Using HTTP from Within a Java Program
Testing an HTTP Connection
You can use the humble Telnet command-line utility to test out an HTTP connection by specifying the required HTTP port number after the hostname on the command line. The default port number for an HTTP server is 80, but Tomcat uses 8080 to avoid a clash with any existing Web server running on the same host. The following command shows how to trace a connection to a local Tomcat Web server:
> telnet localhost 8080 TRACE * HTTP/1.0 HTTP/1.1 200 OK Content-Type: message/http Content-Length: 19 Date: Tue, 02 Apr 2002 10:21:36 GMT Server: Apache Tomcat/4.0.3 (HTTP/1.1 Connector) TRACE * HTTP/1.0
The first three lines in this example are the ones you type in: the first is the Telnet command, and the next two lines are the HTTP request. The rest of the listing is the response from Tomcat, which includes the request as the body of the message.
When you start up Telnet to connect to an HTTP server, you will not receive a prompt. Simply type in your HTTP request and press the Enter key twice; once to end the request line, and once to enter the blank line that marks the end of the request header fields. You might need to switch local echo on for your Telnet utility in order to see the HTTP request line you type in. You can do this by typing CTRL-] after starting Telnet to get to the Telnet prompt, and then entering the command set local_echo. Entering a blank line to the Telnet prompt will enable you to resume the Telnet session to the HTTP server.