javaandroidlast-modifiedif-modified-since

How to know a webpage last-modified date & time in Android Java


How can I know the date a webpage last-modified using Android Java? or how I can request for

If-Modified-Since: Allows a 304 Not Modified to be returned if content is unchanged

using http headers?


Solution

  • I could do it this way:

    URL url = null;
            try {
                url = new URL("http://www.example.com/example.pdf");
            } catch (MalformedURLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            HttpURLConnection httpCon = null;
            try {
                httpCon = (HttpURLConnection) url.openConnection();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    
            long date = httpCon.getLastModified();