1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| Uses WinInet;
{----------------------------------------------------------------}
Function CheckUrl(url: String): Boolean;
Var
hSession, hURL: HInternet;
sAppName: String;
dwCodeLen, dwIndex: Cardinal;
dwCode: Array[1..20] Of Char;
res: PChar;
Begin
Result := False;
sAppName := ExtractFileName(Application.ExeName);
hSession := InternetOpen(PChar(sAppName), INTERNET_OPEN_TYPE_PRECONFIG, Nil, Nil, 0);
Try
hURL := InternetOpenURL(hSession, PChar(url), Nil, 0, 0, 0);
Try
dwCodeLen := 10;
dwIndex := 0;
HttpQueryInfo(hURL, HTTP_QUERY_STATUS_CODE, @dwcode, dwCodeLen, dwIndex);
res := PChar(@dwcode);
Result := ((res = '200') Or (res = '302'));
Finally
If (Assigned(hURL)) Then InternetCloseHandle(hURL);
End;
Finally
If (Assigned(hSession)) Then InternetCloseHandle(hSession);
End;
End;
{----------------------------------------------------------------}
Procedure TForm1.Button1Click(Sender: TObject);
Begin
If (CheckUrl('http://sub0.developpez.com/')) Then
Label1.Caption := 'Connected'
Else
Label1.Caption := 'Not Connected';
End; |