• Post Reply Bookmark Topic Watch Topic
  • New Topic

Reading lastModified from a File located in a Web Server  RSS feed

 
Alfredo Delgado Sanchez
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

i want to retrieve a File from a WebServer. That's possible, using URL and InputStream Classes. But, it is possible to read the last modified date from this file also?

Best Regards

ADS
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The last modified date should be in the headers when you retrieve the file. You can send a HEAD request and get only the headers without getting the whole file. Try viewing headers HERE or with a sniffer tool to see what's going back & forth.
 
Alfredo Delgado Sanchez
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

thanks for your answer!

In the page you give me (http://web-sniffer.net) I GET a HEAD from a file and comes back the last modified date. Do you have Java code to do this?

Best Regards

ADS
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you can send HEAD and read the headers all with the URL / HttpURLConnection combination. I have to admit I've not tried either of those. I've sent GET and POST and read the response body, but not HEAD and the response headers. See if you can work it out from the doc and the Sun networking tutorials. Show us what you make!
 
Alfredo Delgado Sanchez
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody,

many thanks for your help!

I have used the Jakarta HttpClient for this (http://jakarta.apache.org/commons/httpclient/). And it works fine!

The code I write was:



This API has also the possible to convert a String Date with the HTTP 1.1 format to use in Java. The class is DateUtil, method parseDate.

Best Regards

ADS
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!