Thema: FreePascal URL wininet ermitteln

Einzelnen Beitrag anzeigen

Pascal95
(Gast)

n/a Beiträge
 
#4

AW: URL wininet ermitteln

  Alt 23. Sep 2011, 13:44
Ich habe es geschafft !



Ohne Deine Hilfe hätte ich das nicht geschafft !

Als Dank dafür veröffentliche ich den Code, um die Weiterleitungs-URL herauszufinden:
Delphi-Quellcode:
function GetRedirection(const Url: string): string;
var
  hInet: HINTERNET;
  hConnect: HINTERNET;
  infoBuffer: array [0..512] of char;
  dummy: DWORD;
  bufLen: DWORD;
  okay: longbool;
  reply: string;
begin
  Result := '?';

  hInet := InternetOpen(PChar('a browser...'), INTERNET_OPEN_TYPE_PRECONFIG,
    nil, nil, 0);

  hConnect := InternetOpenUrl(hInet, PChar(Url), nil, 0, INTERNET_FLAG_RELOAD +
    INTERNET_FLAG_NO_AUTO_REDIRECT, 0);

  if not Assigned(hConnect) then
    Exit
  else
  begin
    dummy := 0;
    bufLen := Length(infoBuffer);
    okay := HttpQueryInfo(hConnect, HTTP_QUERY_STATUS_CODE,
      @infoBuffer[0], bufLen, dummy);
    if not okay then
      Exit
    else
    begin
      reply := infoBuffer;
      if (reply = '301') or (reply = '302') then
      begin
        dummy := 0;
        bufLen := Length(infoBuffer);
        okay := HttpQueryInfo(hConnect, HTTP_QUERY_LOCATION,
          @infoBuffer[0], bufLen, dummy);
        if not okay then
          Exit
        else
        begin
          reply := infoBuffer;
          if reply <> 'then
            Result := reply;
        end;
      end
      else
        Exit;
    end;
    InternetCloseHandle(hConnect);
  end;
  InternetCloseHandle(hInet);
end;
Hoffentlich kann jemand das gebrauchen !

Nochmals vielen Dank,
liebe Grüße,
Pascal
  Mit Zitat antworten Zitat