I wrote a Delphi function retrieving a web page from another application.
This works fine when I use a file to store the information via
Result := URLDownloadToFile( nil, PChar( XmlUrl), PChar( XmlFileName_), 0, nil);
When I use an URLOpenBlocking-stream I get the correct information but the second time I do a request to the webserver I get the old page although the page has changed.
Does anybody have an idea what could be the cause ?
function MyDownloadToBlockingSteam( URL : String; Var bsXmlStr : AnsiString): LongInt;
var
ppStream : ActiveX.IStream;
statstg : TStatStg;
dwRead : Integer;
begin
Result := 1;
bsXmlStr := '';
If (URLOpenBlockingStream(nil, PChar(URL), ppStream, 0, nil) = S_OK) then
Begin
// Resource protection
try
if (ppStream.Stat(statstg, STATFLAG_NONAME) = S_OK) then // Get the stat from the IStream interface
begin
if (statstg.cbSize > 0) then // Make sure size is greater than zero
begin
SetLength ( bsXMLStr, statstg.cbSize+1 );
Result := ppStream.Read( @bsXMLStr[1], statstg.cbSize, @dwRead); // Read from the stream
end;
end;
finally
ppStream:=nil; // Release the IStream interface
end;
end;//If ..
end;
Consider using InternetOpenUrl()
and InternetReadFile()
instead. It will take a few extra lines of coding to manually accomplish the same thing that URLOpenBlockingStream()
does internally for you, but InternetOpenUrl()
does have a dwFlags
parameter which accepts an INTERNET_FLAG_RELOAD
flag to force downloading the latest data from the URL. URLOpenBlockingStream()
does not have that option.