Sample code for 30+ languages & platforms
Xbase++ Requires Chilkat v11.0.0+

Get the Last-Modified Date Before HTTP Download

See more HTTP Examples

Demonstrates how to send a HEAD request to get the last-modified date of a file on a web server (without downloading the file).

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oHttp
LOCAL oResp
LOCAL cLastModStr
LOCAL oCkdt
LOCAL oDt

nSuccess := 0

//  This example assumes the Chilkat API to have been previously unlocked.
//  See Global Unlock Sample for sample code.

oHttp := CreateObject("Chilkat.Http")

oResp := CreateObject("Chilkat.HttpResponse")
nSuccess := oHttp:HttpNoBody("HEAD", "https://www.chilkatsoft.com/hamlet.xml", oResp)
IF (nSuccess == 0)
    ? oHttp:LastErrorText
    oHttp:destroy()
    oResp:destroy()
    RETURN
ENDIF

//  Examine the response header.
? oResp:Header

//  Here is a sample response header:

//  	Content-Length: 279658
//  	Content-Type: text/xml
//  	Last-Modified: Thu, 12 May 2016 15:14:08 GMT
//  	Accept-Ranges: bytes
//  	ETag: "c1cd8bee60acd11:0"
//  	Server: Microsoft-IIS/8.5
//  	X-Powered-By: ASP.NET
//  	X-Powered-By-Plesk: PleskWin
//  	Date: Thu, 25 Jul 2019 16:40:54 GMT

//  Get the Last-Modified header.
cLastModStr := oResp:GetHeaderField("Last-Modified")
//  If the header exists...
IF (oResp:LastMethodSuccess == 1)
    //  Parse the RFC822 format date/time string
    oCkdt := CreateObject("Chilkat.CkDateTime")
    oCkdt:SetFromRfc822(cLastModStr)

    //  If we want to access individual date/time parts (in the local timezone)
    oDt := CreateObject("Chilkat.DtObj")
    oCkdt:ToDtObj(1, oDt)

    ? "day/month/year = " + Str(oDt:Day) + "/" + Str(oDt:Month) + "/" + Str(oDt:Year)
ENDIF

oHttp:destroy()
oResp:destroy()
oCkdt:destroy()
oDt:destroy()