본문 바로가기

Academy I/Tech Academy

[Delphi]실제 웹페이지 주소연결을 체크하는 방법

use WinIet;


function InternetConnected: Boolean;
var
  InetState: DWORD;
  hHttpSession, hReqUrl: HInternet;


begin
        Result:= InternetGetConnectedState(@InetState, 0);


        if (Result and (InetState and INTERNET_CONNECTION_CONFIGURED =

                               INTERNET_CONNECTION_CONFIGURED)) then  begin

           hHttpSession:= InternetOpen('agency', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);

           try
               hReqUrl:= InternetOpenURL(hHttpSession, PChar(체크할 URL), nil, 0, 0, 0);
               Result := hReqUrl <> nil;
               InternetCloseHandle(hReqUrl);
           finally
                   InternetCloseHandle(hHttpSession);
           end;//end try


           end

           else if (InetState and INTERNET_CONNECTION_OFFLINE =

                       INTERNET_CONNECTION_OFFLINE) then
                   Result := False;

end;