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?

