Domanda

I'm currently writing some update polling stuff. I try to avoid writing even a simple REST-Interface for this (we're using much REST, still I'm not sure this is necessary here. Why write an interface for functionality already there?)

My idea was to open an HttpUrlConnection and check headers for file's last modified date. Apache obviously sends "Last-Modified" date in UTC. After checking the header I'd close the connection without actually retrieving the body. I only fear that this might bring up errors in Apache log, which would be quite inconvenient. I just wanted to ask for you opinion. Do you think this might work? Better ideas?

(I need system proxy support, so my only option seems to be HttpUrlConnection.)

Regards, Stev

È stato utile?

Soluzione

If you look at the HTTP protocol, you'll see that it has a HEAD request which does just what you need. The default for HTTP requests in the Java runtime is GET and it's not really easy to change that.

Have a look at HttpClient for a framework which allows you to send any kind of request.

Altri suggerimenti

You are almost right but your task is even simpler that what you are explaining. There is special HTTP method named HEAD. You just have to create the same request you need to retrieve your data but use HEAD instead of GET

This sounds pretty much, what the HEAD method in HTTP is for.

Citing from Wikipedia:

HEAD Asks for the response identical to the one that would correspond to a GET request, but without the response body. This is useful for retrieving meta-information written in response headers, without having to transport the entire content.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top