Board index » delphi » downloading a file using WinInet

downloading a file using WinInet


2004-07-22 12:06:13 AM
delphi137
I'm trying to download a file using http. However, httpQueryInfo returns
false all the time. I am using this code for testing:
=================================================
hSession := InternetOpen( PChar('SomeAgent'),
INTERNET_OPEN_TYPE_PRECONFIG, Nil, Nil, 0 );
hConnect := InternetConnect( hSession, PChar('127.0.0.1'),
INTERNET_DEFAULT_HTTP_PORT,
nil,nil, INTERNET_SERVICE_HTTP, 0, 0 );
RequestMethod := 'GET';
InternetFlag := INTERNET_FLAG_RELOAD;
AcceptType := PChar('Accept: */*');
hRequest := HttpOpenRequest(hConnect, RequestMethod,
PChar('httpDownload/Downloads/AutoUpdats/8/updates.xml'),
'HTTP/1.0' , PChar(''), @AcceptType,
InternetFlag, 0 );
HttpSendRequest( hRequest, Nil, 0, Nil, 0 );
BufferLength := 1024;
GetMem(Buffer, BufferLength);
FDownloadResult := HttpQueryInfo(hRequest, HTTP_QUERY_CONTENT_LENGTH,
Buffer,
BufferLength, Index );
=================================================
I can not seem to find any info on httpQueryInfo either for debugging
purposes. Can anyone point me to some info on httpQueryInfo or what's wrong
with my code.
Thanks,
Bill N
 
 

Re:downloading a file using WinInet

"Bill N" <XXXX@XXXXX.COM>writes
Quote
RequestMethod := 'GET';
Since you are only retreiving a header file and not downloading the actual
file, use 'HEAD' instead of 'GET'.
Quote
BufferLength := 1024;

GetMem(Buffer, BufferLength);
You are requesting the content length. That can be returned as a DWORD
rather than a string. Try this:
var
ContentLength, BufferLength: DWORD;
//...
BufferLength := SizeOf(DWORD);
HttpQueryInfo(hRequest, HTTP_QUERY_CONTENT_LENGTH or
HTTP_QUERY_FLAG_NUMBER, @ContentLength, BufferLength, Index );
Quote
PChar('httpDownload/Downloads/AutoUpdats/8/updates.xml')
That is an incomplete URL. Assuming that you are trying to retreive
information about the following file:
127.0.0.1/httpDownload/Downloads/AutoUpdats/8/updates.xml
Then at the very least, you should prefix the path with a leading backslash:
PChar('/httpDownload/Downloads/AutoUpdats/8/updates.xml')
Gambit
 

Re:downloading a file using WinInet

...'httpDownload/Downloads/AutoUpdats/8/updates.xml'
Seeing that you are using the file 'updates.xml' and you appear to be
doing some sort of update handling, then my guess is you're using the
application auotupdate+ frmo www.autoupdateplus.com. If that is the
case and you're having problems you would probably be better off to
email them directly.