Advertisement
Gov_777

CheckUrl

Oct 5th, 2016
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 0.79 KB | None | 0 0
  1. uses wininet;
  2.  
  3. function CheckUrl(url: string): boolean;
  4. var
  5.   hSession, hfile, hRequest: hInternet;
  6.   dwindex, dwcodelen: dword;
  7.   dwcode: array [1..20] of char;
  8.   res: pchar;
  9. begin
  10.   if pos('http://', lowercase(url)) = 0 then
  11.     url := 'http://'+url;
  12.   Result := false;
  13.   hSession := InternetOpen('InetURL:/1.0', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
  14.   if assigned(hsession) then
  15.   begin
  16.     hfile := InternetOpenUrl(hsession, pchar(url), nil, 0, INTERNET_FLAG_RELOAD, 0);
  17.     dwIndex := 0;
  18.     dwCodeLen := 10;
  19.     HttpQueryInfo(hfile, HTTP_QUERY_STATUS_CODE, @dwcode, dwcodeLen, dwIndex);
  20.     res := pchar(@dwcode);
  21.     result := (res = '200') or (res = '302');
  22.     if assigned(hfile) then
  23.       InternetCloseHandle(hfile);
  24.     InternetCloseHandle(hsession);
  25.   end;
  26. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement