Review of HTTP

Team-Fly

This section presents a brief review of the Hypertext Transfer Protocol. The whole story is in RFC 2616; this section covers the essentials.

Requests and Responses

HTTP is built around requests and responses. A client sends a request for a server-something like, "Please give me such-and-so HTML page." The server sends back a response-something like, "Here's the file," or "I don't know what you're talking about."

Requests and responses have two parts: headers and content. If you type a URL into your browser, the browser creates an HTTP request (mostly headers) and sends it to a server. The server finds the requested file and sends it back in an HTTP response. The response headers describe things like the type of Web server, the file type of the response, the length of the response, and other information. The response content is the data of the file itself.

Parameters

Browsers and other HTTP clients request specific named resources from HTTP servers. In addition, clients can pass parameters to the server. Parameters are simple name and value pairs. For example, a client might send a "userid" parameter with a value of "jonathan" to a server.

When a browser is the HTTP client, parameters are generally collected from HTML forms. You've seen these forms, like the one where you fill in your shipping address and your credit card number. Form values are sent as parameters to a Web server when you click the Submit or Next button on the form.

The client encodes parameters before they are sent to the server. Parameters are passed as name and value pairs; multiple parameters are separated by ampersands. The exact way that parameters are encoded is documented in the J2SE documentation for java.net.URLEncoder. The rules are relatively simple.

  • The space character is converted to a plus (+) sign.

  • The following characters remain unchanged: lowercase letters a through z, uppercase letters A through Z, the numbers 0 through 9, the period (.), the hyphen (-), the asterisk (*), and the underscore (_).

  • All other characters are converted into '%xy,' where 'xy' is a hexadecimal number that represents the low eight bits of the character.

GET, HEAD, and POST

The simplest HTTP operation is GET. This is what happens when you type a URL into your browser. The browser says, "GET me this URL," and the server responds with the headers and content of the response.

With a GET request, parameters are added to the end of the URL in encoded form. For example, suppose the following URL maps to a servlet or some other server-side component of your application:

http://jonathanknudsen.com/simple

Adding a parameter is easy. If you want to pass a parameter with a name of "user" and a value of "jonathan," you would use the following URL:

http://jonathanknudsen.com/simple?user=jonathan

Additional name and value pairs can be added, separated by ampersands:

http://jonathanknudsen.com/simple?user=jonathan&zip=08540&day=saturday

The HEAD operation is identical to GET, but the server sends back only the headers of the response.

POST is basically the same as GET, but parameters are handled differently. Instead of being pasted on the end of the URL, as they are with GET, the parameters are passed as the body of the request. They are encoded in the same way.


Team-Fly


Wireless Java. Developing with J2ME
ColdFusion MX Professional Projects
ISBN: 1590590775
EAN: 2147483647
Year: 2000
Pages: 129

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net