Java Reference
In-Depth Information
The HttpURLConnection class transparently supports HTTP Keep-Alive unless you ex‐
plicitly turn it off. That is, it will reuse sockets if you connect to the same server again
before the server has closed the connection. Once you know you're done talking to a
particular host, the disconnect() method enables a client to break the connection:
public abstract void disconnect ()
If any streams are still open on this connection, disconnect() closes them. However,
the reverse is not true. Closing a stream on a persistent connection does not close the
socket and disconnect.
Handling Server Responses
The first line of an HTTP server's response includes a numeric code and a message
indicating what sort of response is made. For instance, the most common response is
200 OK, indicating that the requested document was found. For example:
HTTP/1.1 200 OK
Cache-Control:max-age=3, must-revalidate
Connection:Keep-Alive
Content-Type:text/html; charset=UTF-8
Date:Sat, 04 May 2013 14:01:16 GMT
Keep-Alive:timeout=5, max=200
Server:Apache
Transfer-Encoding:chunked
Vary:Accept-Encoding,Cookie
WP-Super-Cache:Served supercache file from PHP
<HTML>
<HEAD>
rest of document follows...
Another response that you're undoubtedly all too familiar with is 404 Not Found, in‐
dicating that the URL you requested no longer points to a document. For example:
HTTP/1.1 404 Not Found
Date: Sat, 04 May 2013 14:05:43 GMT
Server: Apache
Last-Modified: Sat, 12 Jan 2013 00:19:15 GMT
ETag: "375933-2b9e-4d30c5cb0c6c0;4d02eaff53b80"
Accept-Ranges: bytes
Content-Length: 11166
Connection: close
Content-Type: text/html; charset=ISO-8859-1
<html>
<head>
<title>Lost ... and lost</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
Search WWH ::




Custom Search