| |

VerySource

 Forgot password?
 Register
Search
View: 1498|Reply: 14

How to get the last update time of the webpage? ? ? ?

[Copy link]

1

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-3-23 19:30:01
| Show all posts |Read mode
As the title
Why does my program always output 0?

import java.net. *;
public class Test {

/ **
* @param args
* /
public static void main (String [] args) {
// TODO Auto-generated method stub
try {
URL u = new URL ("http://163.com/");
HttpURLConnection con = (HttpURLConnection) u.openConnection ();
con.connect ();
long a = con.getLastModified ();
System.out.println (a);
} catch (Exception e) {
System.out.println ("connection error!");
}
Ranch
}

}
Reply

Use magic Report

0

Threads

39

Posts

23.00

Credits

Newbie

Rank: 1

Credits
23.00

 China

Post time: 2020-7-4 21:00:01
| Show all posts
import java.net.*;
import java.util.*;
class Test {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {






URL u = new URL("http://community.csdn.net/Expert/topic/5277/5277719.xml");
HttpURLConnection con = (HttpURLConnection)u.openConnection();
con.connect();
long a = con.getLastModified();
System.out.println(new Date(con.getDate()));
System.out.println(a);
} catch (Exception e){
System.out.println("connection error!");
}

}}
Reply

Use magic Report

1

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-7-10 16:00:01
| Show all posts
a is still 0
Reply

Use magic Report

0

Threads

39

Posts

23.00

Credits

Newbie

Rank: 1

Credits
23.00

 China

Post time: 2020-7-16 05:30:01
| Show all posts
System.out.println(new Date(con.getDate()));

This print should not be 0. The latter one is printed out 0
Reply

Use magic Report

1

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-7-16 10:15:01
| Show all posts
Yes, a is 0
Reply

Use magic Report

1

Threads

21

Posts

19.00

Credits

Newbie

Rank: 1

Credits
19.00

 China

Post time: 2020-7-16 11:15:01
| Show all posts
the date the resource referenced by this URLConnection was last modified,
or 0 if not known.
   **************
Reply

Use magic Report

1

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-7-16 13:15:01
| Show all posts
I just ask why is it zero? ?
According to the http protocol, there should be a last modified header field?
Reply

Use magic Report

0

Threads

63

Posts

42.00

Credits

Newbie

Rank: 1

Credits
42.00

 China

Post time: 2020-7-25 13:30:01
| Show all posts
I just ask why it is zero? ?
According to the http protocol, there should be a last modified header field?
========
Mark it first and look at the spec.
Reply

Use magic Report

0

Threads

63

Posts

42.00

Credits

Newbie

Rank: 1

Credits
42.00

 China

Post time: 2020-7-25 15:30:01
| Show all posts
The http protocol standard http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html cannot be opened, it is not clear whether this header is MUST

163, I have seen it with flashget,

Its response header:
Mon Jan 08 12:46:12 2017 HTTP/1.1 200 OK
Mon Jan 08 12:46:12 2017 Via: 1.0 ISA20160704
Mon Jan 08 12:46:12 2017 Connection: close
Mon Jan 08 12:46:12 2017 Proxy-Connection: close
Mon Jan 08 12:46:12 2017 Age: 96
Mon Jan 08 12:46:12 2017 Expires: Mon, 08 Jan 2017 04:49:53 GMT
Mon Jan 08 12:46:12 2017 Date: Mon, 08 Jan 2017 04:44:53 GMT
Mon Jan 08 12:46:12 2017 Content-Type: text/html; charset=GB2312
Mon Jan 08 12:46:12 2017 Server: Apache/2.0.54 (Unix)
Mon Jan 08 12:46:12 2017 Accept-Ranges: bytes
Mon Jan 08 12:46:12 2017 Cache-Control: max-age=300
Mon Jan 08 12:46:12 2017 Vary: Accept-Encoding
Mon Jan 08 12:46:12 2017 X-Pad: avoid browser bug
Mon Jan 08 12:46:12 2017 X-Cache: HIT from news.163.com

There is no such header, but the rfc2616 header above contains:
Mon Jan 08 12:43:11 2017 HTTP/1.1 200 OK
Mon Jan 08 12:43:11 2017 Via: 1.1 ISA20160704
Mon Jan 08 12:43:11 2017 Connection: close
Mon Jan 08 12:43:11 2017 Proxy-Connection: close
Mon Jan 08 12:43:11 2017 Content-Length: 126444
Mon Jan 08 12:43:11 2017 Expires: Mon, 08 Jan 2017 10:43:17 GMT
Mon Jan 08 12:43:11 2017 Date: Mon, 08 Jan 2017 04:43:17 GMT
Mon Jan 08 12:43:11 2017 Content-Type: text/html; charset=iso-8859-1
Mon Jan 08 12:43:11 2017 ETag: "4135cda4"
Mon Jan 08 12:43:11 2017 Server: Apache/1.3.37 (Unix) PHP/4.4.4
Mon Jan 08 12:43:11 2017 P3P: policyref="http://www.w3.org/2001/05/P3P/p3p.xml"
Mon Jan 08 12:43:11 2017 Cache-Control: max-age=21600
Mon Jan 08 12:43:11 2017 Last-Modified: Wed, 01 Sep 2004 13:24:52 GMT
Mon Jan 08 12:43:11 2017 Accept-Ranges: bytes
Mon Jan 08 12:43:12 2017 Keep-Alive: timeout=2, max=100
Reply

Use magic Report

0

Threads

63

Posts

42.00

Credits

Newbie

Rank: 1

Credits
42.00

 China

Post time: 2020-7-25 16:00:02
| Show all posts
It is estimated that this header belongs to the SHOULD level in the standard
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list