To read a header of a remote file, it is necessary to process the full file?

271 Views Asked by At

I have a webservice that returns resources, text or images.

I'm getting the header of these resources, and the problem is that when i get the header of a text, the header comes in miliseconds, but when i get the header of a image, the header takes two or three seconds to come.

¿Why is this possible? Is the java method getHeaderField processing the full object before returning the field of the header?

this is my sample code:

URLConnection connection;
URL url = new URL(this.url);
connection = url.openConnection();
String date = connection.getHeaderField("Last-Modified"));
1

There are 1 best solutions below

0
On

use http HEAD not GET

You can set this by calling connection.setRequestMethod("HEAD") on your (HTTP)URLConnection object.

See

http://docs.oracle.com/javase/7/docs/api/java/net/HttpURLConnection.html#setRequestMethod(java.lang.String)