URLConnection.getLastModified()

No matter the site I test, the getLastModified() always returns 0 (unknown).  Does anyone have any ideas why?

URL test = new URL("http://www.hotmail.com");
URLConnection conn = test.openConnection();
System.out.println(conn.getLastModified());

Thanks,
david

lomidienAsked:
Who is Participating?
 
CEHJCommented:
Unless the page is static (relatively rare) it usually will return 0
0
 
lomidienAuthor Commented:
well this is bad news indeed.  Let me describe something and perhaps you might have an alternate viewpoint for a different way to go about it.

I'm using the Google api to perform a search....the results are in the neighborhood of 13,000 and I log each url to a database.  This is a news retrieval system for the U.N. and I really don't want to pull down all 13,000 entries each day just to find out if they're different or not...so I was hoping for the last modified date to be useful to me, but it seems that it won't be.

Is there another idea that perhaps is better than what i've got?

Thanks,
David
0
 
Peter KwanAnalyst ProgrammerCommented:
If the header field Last-Modified in the url does not exists, 0 will be returned. This does not matter whether the page is static or not.

lomidien, you may filter out some URLs by using the following method.

Here is an example:

Calender cal = Calendar.getInstance();
c.add(Calendar.DATE, -1);
URL test = new URL("http://www.hotmail.com");
HttpURLConnection conn = (HttpURLConnection)test.openConnection();

if (conn.getResponseCode() == 304)
   // not modified
else
  // do whatever you want
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
CEHJCommented:
>>This does not matter whether the page is static or not

That's true in an absolute way but it's generally more likely not to have it if the response is dynamic

>>Calender cal = Calendar.getInstance();

is not used in your code example btw.

lomidien - if you're implementing this in your program, you should have a sound knowledge of the protocol:

http://www.w3.org/Protocols/rfc2616/rfc2616.html
0
 
Peter KwanAnalyst ProgrammerCommented:
Sorry, typo:

Calender cal = Calendar.getInstance();
cal.add(Calendar.DATE, -1);
UR test = new URL("http://www.hotmail.com");
HttpURLConnection conn = (HttpURLConnection)test.openConnection();
conn.setIfModifiedSince(cal.getTimeInMillis());
0
 
CEHJCommented:
Here's a gentle introduction to these matters:

http://www.edginet.org/techie/website/http.html
0
 
CEHJCommented:
:-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.