Thema: Delphi Prüfen ob Datei online

Einzelnen Beitrag anzeigen

win568

Registriert seit: 8. Sep 2008
121 Beiträge
 
#4

AW: Prüfen ob Datei online

  Alt 22. Mai 2012, 09:58
Kleines Snippet

Code:
function CheckUrl(url:string):Boolean;
var hSession, hfile: hInternet;
    dwindex,dwcodelen :dword;
    dwcode:array[1..20] of char;
    res : pchar;
begin
  Result := FALSE;
  if Pos('http://',lowercase(url)) = 0 then begin
    url := 'http://'+url;
  end;
  hSession := InternetOpen('InetURL:/1.0', INTERNET_OPEN_TYPE_PRECONFIG,NIL, NIL, 0);
  if Assigned(hsession) then begin
    hfile := InternetOpenUrl(hsession, PCHAR(url), NIL, 0, INTERNET_FLAG_RELOAD, 0);
    dwIndex := 0;
    dwCodeLen := 10;
    HttpQueryInfo(hfile, HTTP_QUERY_STATUS_CODE, @dwcode, dwcodeLen, dwIndex);
    res := pchar(@dwcode);
    Result:= (res ='200') or (res ='302');
    if Assigned(hfile) then begin
      InternetCloseHandle(hfile);
    end;
    InternetCloseHandle(hsession);
  end;
end;
  Mit Zitat antworten Zitat