Jeg lavede et program der kan hente "last modified" felt fra headeren på en html side. Det virker sådan set ok, hvis siden sender et brugbart felt, men det er der ikke ret mange der gør :-(
tv2.dk sender f.ex. et felt, men det er altid sat til at være nu.
dr.dk og www.udvikleren.dk sender ingenting
Min egen hjemmeside (home20.inet.tele.dk /midgaard/sample.html) sender et gyldig tid.
#include <windows.h>
#include <wininet.h>
#include <iostream>
int main(int argc, char *argv[])
{
if(argc != 3)
{
std::cout << "Usage: " << argv[0] << " server page" << std::endl;
std::cout << " E.G tv2.dk /" << std::endl;
return 0;
}
HINTERNET Internet = InternetOpen("My Url Browser", INTERNET_OPEN_TYPE_DIRECT, 0, 0, 0);
if(!Internet)
{
std::cout << "Failed to open internet: " << GetLastError() << std::endl;
return 1;
}
HINTERNET Connect = InternetConnect(Internet,
argv[1],
INTERNET_INVALID_PORT_NUMBER,
"",
"",
INTERNET_SERVICE_HTTP,
0,
0);
HINTERNET HttpFile = HttpOpenRequest(Connect, "HEAD", argv[2], 0, 0, 0, 0, 0);
if(!HttpFile)
{
std::cout << "Failed to open request" << std::endl;
return 1;
}
if(!HttpSendRequest(HttpFile, 0, 0, 0, 0))
{
std::cout << "Failed to send request" << std::endl;
return 0;
}
unsigned long index = 0;
char Buffer[64*1024];
unsigned long bufsize = sizeof(Buffer);
if(!HttpQueryInfo(HttpFile, HTTP_QUERY_LAST_MODIFIED, Buffer, &bufsize, &index))
{
std::cout << "Failed to Query Information" << std::endl;
return 1;
}
std::cout << "Status: " << Buffer << std::endl;
InternetCloseHandle(HttpFile);
InternetCloseHandle(Connect);
InternetCloseHandle(Internet);
}