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

2019-05-29 01:08发布

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?

1条回答
聊天终结者
2楼-- · 2019-05-29 01:33

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();
查看更多
登录 后发表回答