|
| |||||||||
| Tags: date, function, java, method, programming language |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| 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);
} Last edited by New ID : 18-01-2010 at 01:00 PM. |
|
#2
| ||||
| ||||
| 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 |
|
#3
| |||
| |||
| 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
| ||||
| ||||
| 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:
|
|
#5
| |||
| |||
| 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
| ||||
| ||||
| 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. |
![]() |
|
| Thread Tools | Search this Thread |
| |
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 |