News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

How does one get the date/time of a file on a site?

Started by Jimg, August 11, 2009, 02:39:45 PM

Previous topic - Next topic

Jimg

I am using URLDownloadToFile to download files from an internet site.
Is there some way to get the date/time the file was uploaded to the site?

drizz

The truth cannot be learned ... it can only be recognized.

dedndave

i was just tryin to find that info
it does not appear to be a field in the response header...
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

if there is a guy that knows how to do it, it is Gary White (Mr. Php)
try poking around on his site (or even e-mailing him)
http://apptools.com/

japheth

I also vote for "last-modified" in the http header.

If you're not using winsockets (which is the preferable way IMO), then function HttpQueryInfo( ..., HTTP_QUERY_LAST_MODIFIED, ... ) might be used. It probably won't work with this ancient URLDownload-stuff, but here is a code snippet which shows the context for usage of HttpQueryInfo():


OnRead proc uses ebx hWnd:HWND, pszUrl:LPSTR

local hInternet:HINTERNET
local hUrl:HINTERNET
local ib:INTERNET_BUFFERS
local estrm:EDITSTREAM
local dwIndex:DWORD
local dwBufLength:DWORD
local szText[128]:byte

       ...
invoke InternetOpen, CStr("WinINetASM"),INTERNET_OPEN_TYPE_DIRECT,\
NULL, NULL, 0
.if (eax == NULL)
invoke GetLastError
mov g_dwLastError,eax
mov g_pszError,CStr("InternetOpen failed [%X]")
xor eax,eax
ret
.endif
mov hInternet,eax

invoke InternetOpenUrl, hInternet, pszUrl, NULL, NULL,\
INTERNET_FLAG_RELOAD, CONTEXT_ID
.if (eax == NULL)
invoke GetLastError
mov g_dwLastError,eax
invoke InternetCloseHandle, hInternet
mov g_pszError,CStr("InternetOpenUrl failed [%X]")
xor eax,eax
ret
.endif
mov hUrl, eax

mov dwIndex,0
mov dwBufLength, 10000h
invoke HttpQueryInfo, hUrl, HTTP_QUERY_RAW_HEADERS_CRLF,
g_pszHeader, addr dwBufLength, addr dwIndex

invoke ZeroMemory, addr ib, sizeof ib
mov ib.dwStructSize, sizeof INTERNET_BUFFERS
mov eax,g_pszBuffer
mov ib.lpvBuffer, eax
mov ib.dwBufferLength, BUFLENGTH

invoke InternetReadFileEx, hUrl, addr ib, 0, CONTEXT_ID
.if (eax)
invoke Show, hWnd
mov eax,1
.else
invoke GetLastError
mov g_dwLastError,eax
        ...


dedndave

did not see that field, Drizz and Jeremy - thanks
i looked and looked, too - lol

Jimg

Thanks guys, it worked.  Here's what I finally ended up with-
.data
urlx db "http://www.physicsxxi.com/CurrentImages/P1AME20090810IC0.png",0
.code

testurl proc
    local hUrl,hiopen,hqibuff[16],hqisize,index,contextid

    inv InternetOpen,addr ProgName,INTERNET_OPEN_TYPE_DIRECT,0,0,0
    or eax,eax
    jz testurlerr
    mov hiopen, eax

    mov contextid,99
    invoke InternetOpenUrl,hiopen,addr urlx,0,0,INTERNET_FLAG_RELOAD,addr contextid
    or eax,eax
    jz testurlerr

    mov hUrl,eax
    mov index,0
    mov hqisize,64
    invoke HttpQueryInfo, hUrl, HTTP_QUERY_LAST_MODIFIED,addr hqibuff,addr hqisize, addr index
    or eax,eax
    jz testurlerr

    inv MessageBox,hWin,addr hqibuff,0,0
    inv InternetCloseHandle,hUrl

testurlret:
ret
testurlerr:
    call GetErrDescriptionf
    jmp testurlret
   
testurl endp



The only thing I don't understand is the last parameter for the InternetOpen api.  If I put in INTERNET_FLAG_ASYNC, it fails.  If I just put in zero, it works?

Strobe Raver

You're not making long web requests, right? Then, just leave it as zero. That's really my only understanding of the use for INTERNET_FLAG_ASYNC; I could be wrong.