Flag Reload / Cache WinInet

0

I have the following problem, I have a function in Delphi that executes Online a PHP file that provides the SERIAL of the PROGRAM It happens, that when I execute this function it gets the same SERIAL, because it is in the CACHE of the Machine. I know there is a FLAG that does RELOAD on WinInet, something similar to clear the cache, some help?

Follow my code:

    function DownloadSerial(const Origem: string): string;
var
  SessaoHandle, UrlHandle : Pointer;
  TamanhoDados : DWORD;
  Dados : Array[0..1024] of Char;
  ABC: HMODULE;
begin
  Result := '';
  if (not Assigned(@InternetOpenA) or not Assigned(@InternetOpenUrlA) or not Assigned(@InternetReadFile) or not Assigned(@InternetCloseHandle)) then
  begin
    ABC := LoadLibrary( pChar('wininet.dll')) );
    if ABC <> 0 then
    begin
      @InternetOpenA := GetProcAddress(ABC, pChar('InternetOpenA')));
      @InternetOpenUrlA := GetProcAddress(ABC, pChar('InternetOpenUrlA')));
      @InternetReadFile := GetProcAddress(ABC, pChar('InternetReadFile')));
      @InternetCloseHandle := GetProcAddress(ABC, pChar('InternetCloseHandle')));
    end;
  end;

  if (Assigned(@InternetOpenA) and Assigned(@InternetOpenUrlA) and Assigned(@InternetReadFile) and Assigned(@InternetCloseHandle)) then
  begin
    SessaoHandle := InternetOpenA(nil, 0, nil, nil, 0);
    UrlHandle := InternetOpenUrlA(SessaoHandle, pChar(Origem), nil, 0, 0, 0);
    if UrlHandle <> nil then
    begin
      repeat
        InternetReadFile(UrlHandle, @Dados, SizeOf(Dados), TamanhoDados); //saida := saida + lpBuffer;
        Result := Result + string(Dados);
      until TamanhoDados = 0;
    end;
    InternetCloseHandle(UrlHandle);
    InternetCloseHandle(SessaoHandle);
  end;
end;
    
asked by anonymous 21.06.2014 / 17:35

1 answer

1

You can use the flag INTERNET_FLAG_RELOAD to do this. Use this flag when calling the InternetOpenUrl ".

In your case it would look something like this.

SessaoHandle := InternetOpen(nil, INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
UrlHandle := InternetOpenUrlA(SessaoHandle, pChar(Origem), nil, 0, 0, INTERNET_FLAG_RELOAD);

By using this flag you will force the file to be downloaded from the source, not the cache.

    
21.06.2014 / 19:14