Java Reference
In-Depth Information
The server response of the server is
HTTP/1.1 200 OK
Date: Sat, 31 Mar 2001 21:09:48 GMT
Server: Apache/1.3.14 (Unix)
Last-Modified: Tue, 09 Jan 2001 09:29:10 GMT
ETag: "cd610-1fbc-3a5ad9e6"
Accept-Ranges: bytes
Content-Length: 8124
Connection: close
Content-Type: text/html
<html>
...
</html>
The request that is sent back from the server to the client can be split into three sections:
• The response line indicating the protocol version and status code:
HTTP/1.1 200 OK
• The header containing meta-information provided by the server:
Date: Sat, 31 Mar 2001 21:09:48 GMT
Server: Apache/1.3.14 (Unix)
Last-Modified: Tue, 09 Jan 2001 09:29:10 GMT
ETag: "cd610-1fbc-3a5ad9e6"
Accept-Ranges: bytes
Content-Length: 8124
Connection: close
Content-Type: text/html
• The actual content ( entity or resource ):
<html>
...
</html>
The HTTPConnection Interface
The GCF provides a special interface for HTTP connections, the HTTPConnection .
HTTPConnection is a specialization of the ContentConnection interface, which is a
specialization of Connection .
The advantage of specialized HTTP connection is that it provides comfortable access methods to the
header fields of the connection. Only the actual content is transferred using streams. If the socket
protocol is supported for a device, it is also possible to connect to HTTP servers using the socket
protocol. However, in that case, you would need to enter the additional protocol lines manually along
with the actual content of the transfer, as shown in our server socket example in the previous section.
In addition to the access methods derived from the StreamConnection , a ContentConnection
provides the following methods for getting meta-information:
getType() — Returns a String denoting the MIME type of the content, or null if there
is no such information available. In the preceding example, the content type is text/html .
getEncoding() — Returns a String denoting that character encoding is used for the
content, for example UTF-8 . If this information is not available, null is returned. The
encoding information may be used in the InputStreamReader constructor for reading
character-based data.
Search WWH ::




Custom Search