[Tutor] How to update file?

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Sat, 12 Jan 2002 12:07:10 -0800 (PST)


On Sat, 12 Jan 2002, [iso-8859-1] Gustavo C=F3rdova Avila wrote:

> > Here's a small program that'll get the last-modified header if the web
> > server supports it:
> >=20
> > ###
> > import httplib
> > import urlparse
> >=20
> > def getLastModifiedDate(url):
> >     url_pieces =3D urlparse.urlparse(url)
> >     base, path =3D url_pieces[1], url_pieces[2]     ## this can be
> >                                                   ## improved...
> >     conn =3D httplib.HTTPConnection(base)
> >     conn.request("GET", path)
> >     response =3D conn.getresponse()
> >     return response.getheader('last-modified')
> > ###
>=20
> If you're gonna check the date on the remote file (which is on the web
> server), I'd really recommend you use the HEAD method instead of the
> GET method, because GET will bring you the whole file's contents, and
> HEAD won't return the file contents, only the request's HTTP headers,
> which is where the last modification date is.

Thank you!  I had completely forgotten about HEAD.