HttpUrlConnection sends HEAD request as GET

I am writing a Java Http client application and need to submit HEAD requests. I am using the HttpUrlConnection class to generate the requests and process the responses. However, when I try to send a HEAD request, it sends a GET instead with the "method" request header set to "HEAD", which just isn't the same thing.

Here is a snippet of my code:

URL connection = new URL(urlString);

HttpURLConnection serverConnection = (HttpURLConnection) connection.openConnection();

serverConnection.setDoOutput(true);

serverConnection.setDefaultUseCaches(false);

serverConnection.setRequestProperty("method", "HEAD");

serverConnection.setRequestProperty("Accept-Language", "en-US");

serverConnection.setRequestProperty("User-Agent", "Gemini");

serverConnection.setRequestProperty("Connection", "Keep-Alive");

serverConnection.connect();

When I sniff the network I see this URL and request header

GET /docushare/dsweb/Login HTTP/1.1

method: HEAD

The service application is seeing this as a GET because it doesn't know to check the header to see what the request method really is and returns the message-body, which is not the desired behavior for a HEAD request.

What is wrong here? Something I'm doing or is HttpUrlConnection broken in this regard?

[1336 byte] By [PeterDa] at [2007-10-3 9:27:45]
# 1
GET and HEAD aren't request properties: they're the request method. Try serverConnection.setRequestMethod("HEAD");
YAT_Archivista at 2007-7-15 4:42:03 > top of Java-index,Java Essentials,Java Programming...
# 2
Thanks YAT_Archivist.I saw my coding error as I was re-reading my own post. Unfortunately I don't see a DELETE POST function on this forum.
PeterDa at 2007-7-15 4:42:03 > top of Java-index,Java Essentials,Java Programming...