Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , ,

Sponsored Links



Query in function getIfModifiedSince()

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 18-01-2010
Member
 
Join Date: Dec 2009
Posts: 178
Query in function getIfModifiedSince()

Hello,
I have a concern now to get a date change file through a URL. For the moment my code looks like this:
Code:
try {
         URL ts = new URL(monURL);
         URLConnection urlcon = ts.openConnection();
         Date ndt = new Date(urlcon.getIfModifiedSince());
         System.Out.System.out.println(formatter.format(ndt));
 
 } catch (Exception ex) { 
         System.Out.System.out.println(ex);   
 }
With this code, any URL that I put, it gives me the date Jan 01:00:00. The getIfModifiedSince() function is not working exactly as I am expecting it to work. Any one has any idea about this? Thank you in advance

Last edited by New ID : 18-01-2010 at 01:00 PM.
Reply With Quote
  #2  
Old 18-01-2010
opaper's Avatar
Member
 
Join Date: May 2008
Posts: 2,362
Re: Query in function getIfModifiedSince()

Hi,
It means that the method getIfModifiedSince return "0" if the server asks that, you do not manage client cache and therefore does not forward the date of last modification (in this case a web browser always reload the page). That's why you end up with the date of 1 January xxxx (originally for the timestamp). If you want the desired result you need to change that in your code.
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
  #3  
Old 18-01-2010
Member
 
Join Date: Dec 2009
Posts: 178
Re: Query in function getIfModifiedSince()

Hello,
I tested with multiple URLs. They'll all return the same date. Is there a way to tell if the server can retrieve this information? I tested to create a class that extend URLConnection to retrieve the contents of the variable "connected". Basically I'm unable to connect because the variable remains false.
Code:
Public class modsin extends URLConnection {
 
    Public modsin(URL getrul){
        great(getrul);
        System.Out.System.out.println("modifsince"+ Ifmodsin);
    }
    @ Override
    Public void connect() throws IOException {
        try {
        getrul.openConnection();
        System.Out.System.out.println("test"+ connected);
    } catch (Exception ex) {
        System.Out.System.out.println(ex);
    }
    }
}
Reply With Quote
  #4  
Old 18-01-2010
Modifier's Avatar
Member
 
Join Date: Jan 2008
Posts: 1,502
Re: Query in function getIfModifiedSince()

Hello,
IfModifiedSince() is a value sent by the client and not the server. When used it will tell the server not to return the item, if it has been changed meanwhile. In this case the server sends back just a "mistake" (Not Modified). Otherwise it returns the entire document. This allows the browser to check the validity of its cache. If you just want to get the headers you must use the HEAD statement that will never return the contents of the element:
Quote:
URL getrul = new URL("http://www.google.fr/intl/fr_fr/images/logo.gif");
HttpURLConnection http = (HttpURLConnection) getrul.openConnection();
http.setRequestMethod("HEAD");
http.connect();
try {

for (Map.Entry<String, List <String>> entry: http.getHeaderFields().entrySet()) {
System.Out.System.out.println(entry);
}

} finally {
http.disconnect();
}
Hope this will help you.
Reply With Quote
  #5  
Old 18-01-2010
Member
 
Join Date: Dec 2009
Posts: 178
Re: Query in function getIfModifiedSince()

Hello,
In fact the URLs that I use are linked to files (download links for example). With that I want to do is re-download the file if it has changed. My idea is to compare the date of last modification (i.e here it would be the IfModifiedSince) with the date of my last refresh (which is the date of last download). But the coup with the latest information I wonder if this is really the correct the method. I tried to look at the header of my URL, the problem is that there is no parameter "Age" or "Last-Modified" and "Content-length" is 0. Is this the problem of the server configuration or something else? Any advice on this.
Reply With Quote
  #6  
Old 18-01-2010
opaper's Avatar
Member
 
Join Date: May 2008
Posts: 2,362
Re: Query in function getIfModifiedSince()

Hello,
In this case it is up to you to specify the value of IfModifiedSince And is the server that will send or not the file as appropriate, just check the below code, it might help you.
Code:
HttpURLConnection http = (HttpURLConnection) url.openConnection();
http.setIfModifiedSince(date)
		http.connect();
		try {
			switch (http.getResponseCode()) {
			box HttpURLConnection.HTTP_OK:
				/ * Read the InputStream to retrieve the file * /
				break;
			box HttpURLConnection.HTTP_NOT_MODIFIED:
				/ * File has not been modified since nothing to do * /
				break;
			default:
				/ * Other errors * /
				break;
			}
 		} finally {
			http.disconnect();
		}
__________________
The FIFA Manager 2009 PC Game

Last edited by opaper : 18-01-2010 at 01:12 PM.
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Query in function getIfModifiedSince()"
Thread Thread Starter Forum Replies Last Post
Sql query for Date function. horuy Software Development 3 17-11-2010 12:22 AM
c# function equivalent to gettime function in javascript Omaar Software Development 4 10-03-2010 10:44 PM
Want to make query dependent on another query. MACE Software Development 4 01-02-2010 05:22 PM
Turn on MySQL query cache to speed up query performance DMA2Superman Software Development 3 07-07-2009 11:26 AM
Excel function calculations used in MS Access query John MS Office Support 1 23-05-2008 09:52 PM


All times are GMT +5.5. The time now is 07:41 AM.