Reload/Wininet Cache Flag

Asked

Viewed 186 times

0

I have the following problem, I have a function in Delphi that runs online a PHP file that provides the SERIAL of the PROGRAM It happens, that when I run this function it keeps taking the same SERIAL, because it stays in the CACHE of the Machine. I know there is a FLAG that RELOAD in Wininet, something similar to clear the cache, some help ?

Follows 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;

1 answer

1


You can use the flag INTERNET_FLAG_RELOAD to do this. Use this flag when calling the function 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 that flag you will force the file to download from the source, not the cache.

  • Thanks for the help @Sunstreaker, but unfortunately it didn’t work. I put a button that runs that function above. I click once it takes the first serial, I click again, should take the next one from the list, because the previous one has already been deleted, and unfortunately it continues to take the previous one. What could it be? We forgot something ?

  • it worked yes, with that second reply...thanks friend!

  • I am testing now..... let me see if I can adapt here that I already mark the answer. Thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.