Java Reference
In-Depth Information
2. An HTTP header
3. A blank line (two successive carriage return/linefeed pairs)
4. The body
For example, this POST request sends form data to a server:
POST /cgi-bin/register.pl HTTP 1.0
Date: Sun, 27 Apr 2013 12:32:36
Host: www.cafeaulait.org
Content-type: application/x-www-form-urlencoded
Content-length: 54
username=Elliotte+Harold&email=elharo%40ibiblio.org
In this example, the body contains an application/x-www-form-urlencoded data, but
that's just one possibility. In general, the body can contain arbitrary bytes. However, the
HTTP header should include two fields that specify the nature of the body:
• A Content-length field that specifies how many bytes are in the body (54 in the
preceding example)
• A Content-type field that specifies the MIME media type of the bytes ( application/
x-www-form-urlencoded in the preceeding example).
The application/x-www-form-urlencoded MIME type used in the preceding example is
common because it's how web browsers encode most form submissions. Thus it's used
by a lot of server-side programs that talk to browsers. However, it's hardly the only
possible type you can send in the body. For example, a camera uploading a picture to a
photo sharing site can send image/jpeg. A text editor might send text/html. It's all just
bytes in the end. For example, here's a PUT request that uploads an Atom document:
PUT /blog/software-development/the-power-of-pomodoros/ HTTP/1.1
Host: elharo.com
User-Agent: AtomMaker/1.0
Authorization: Basic ZGFmZnk6c2VjZXJldA==
Content-Type: application/atom+xml;type=entry
Content-Length: 322
<?xml version="1.0"?>
<entry xmlns="http://www.w3.org/2005/Atom">
<title>The Power of Pomodoros</title>
<id>urn:uuid:101a41a6-722b-4d9b-8afb-ccfb01d77499</id>
<updated>2013-02-22T19:40:52Z</updated>
<author><name>Elliotte Harold</name></author>
<content>I hadn't paid much attention to Pomodoro...</content>
</entry>
Search WWH ::




Custom Search