• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HTTP HEAD method: how to get the metadata returned

 
Russell Bateman
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not certain I picked the right JavaRanch forum here, but the Apache-Tomcat one seemed pretty Tomcat specific.

My question is really about getting the metadata back from a server promising information via the HEAD method. I have Googled hard, but find no sample code nor enough information other than to know that HeadMethod.getReponseBody() isn't supposed to return anything. And, in the case of the server I'm trying to talk to, it doesn't.

My code is slightly modified GET code (which, as GET code, works fine). I do get returned back from executeMethod() with a 200, so there's no error there. (This is a copy, paste and slightly adjust job here, so I hope I didn't leave anything out.) I just don't know how to get what HEAD is supposed to give me.

Thanks for any help,

Russ Bateman

 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The point of a HEAD request is to get the response headers. If you inspect the array returned by the method.getResponseHeaders() call you'll find various useful information in it (like the size of the body if this were a GET, and the date when it was last modified).
 
Russell Bateman
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much for responding, I had read something about



However, I don't have the HttpConnection as you see from my sample code, and I have not figured out how yet to get it.

I'm also in the dark as to what to do with an instance of HttpState after creating it.

This is why I was looking for some sample code. I readily admit I'm a newbie.

Thanks for any other help you can give.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can get both HttpState and HttpConnection through methods in the HttpClient class (for the connection there's an intermediate step of getting the HttpConnectionManager first). But reading the response body will do no good for HEAD, as you've found out, because the body is empty.
 
Russell Bateman
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My bad: I had used search to find HttpMethod.getResponseHeaders() and stumbled frustratingly again upon HeadMethod.readResponseBody() all over again and didn't recompare the name with what you had written. I stumbled blindly onward. Grrr.

So, to HttpMethod.getResponseHeaders(), there are no arguments I need to pass. That is the answer I was looking for. Thank you for your patience.

Russ Bateman
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic