Results 1 to 6 of 6

Thread: Query in function getIfModifiedSince()

  1. #1
    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.

  2. #2
    Join Date
    May 2008
    Posts
    2,389

    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.

  3. #3
    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);
        }
        }
    }

  4. #4
    Join Date
    Jan 2008
    Posts
    1,521

    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:
    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.

  5. #5
    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.

  6. #6
    Join Date
    May 2008
    Posts
    2,389

    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();
    		}
    Last edited by opaper; 18-01-2010 at 01:12 PM.

Similar Threads

  1. Sql query for Date function.
    By horuy in forum Software Development
    Replies: 3
    Last Post: 17-11-2010, 12:22 AM
  2. Want to make query dependent on another query.
    By MACE in forum Software Development
    Replies: 4
    Last Post: 01-02-2010, 05:22 PM
  3. MySQL query in a query
    By Rail racer in forum Software Development
    Replies: 3
    Last Post: 21-07-2009, 07:06 PM
  4. Turn on MySQL query cache to speed up query performance
    By DMA2Superman in forum Software Development
    Replies: 3
    Last Post: 07-07-2009, 10:26 AM
  5. Excel function calculations used in MS Access query
    By akbar in forum MS Office Support
    Replies: 1
    Last Post: 23-05-2008, 08:52 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,147,487.10458 seconds with 16 queries