|[ Team LiB ]|
The HTTP POST Command
So far, the only HTTP command you have seen in this hour is the GET command. You are aware that another command, the POST command, is frequently used to send form information to the Web server. Technically, the POST command might be used for more than just form data, but form data is by far the most common kind of data sent via POST.
When a browser sends a POST command, the first line of the request looks just like the GET request, except that instead of GET, the command is POST. The difference comes about just after the request header. In a GET request, there is no data after the request header. After the server sees the blank line indicating the end of the header, it processes the request. In a POST request, the browser sends the form data after the header. The format of the data is a series of name=value pairs separated by &s. In addition, the data values are URL-encoded, just like the values in a GET request. Notice, also, that the content type for a POST request is application/x-www-form-urlencoded.
Listing 4.3 shows a bare-bones form that posts its data to the Dumper program so you can see what a POST request looks like.
<html> <body> <form action="http://localhost:1234" method="post"> <input type="text" name="foo" value="Foo!"><br> <input type="text" name="bar" value="Bar?"><br> <input type="text" name="baz" value="<<BAZ>>"><br> <input type="submit"> </form> </body> </html>
Figure 4.6 shows the output from the Dumper program after it receives a POST request.
In Case of Trouble
Notice that a content type and content length are in the request. No matter which direction the data is going, if you are sending content, you need to specify a content type and usually a content length.
|[ Team LiB ]|