From: Roy L. <ro...@ly...> - 2011-11-27 16:18:29
|
I'm currently using function ValidateURL(const URL: string): boolean; var grab: THTTPSend; sl: TStringList; Cntr: integer; Location: string; AddSlash: string; begin if URL = '' then begin Result := False; Exit; end; sl := TStringList.Create; grab := THTTPSend.Create; grab.Timeout := 2000; sl.Text := URL; Result := True; try for Cntr := 0 to sl.Count - 1 do begin if IsURL(sl[Cntr]) then begin if grab.HTTPMethod('GET', sl[Cntr]) then begin if (grab.ResultCode div 100) <> 2 then begin if grab.ResultCode = 302 then begin Location := Copy(grab.Headers.Text, Pos('location:', LowerCase(grab.Headers.Text)) + 9, MaxInt); if 0 <> Pos('opendns.com', LowerCase(Location)) then begin Result := False; Break; end else begin Location := LowerCase(Copy(Location, 1, Pos(#13, Location) - 1)); if 0 <> Pos('?', Location) then begin if URL[Length(URL)] = '/' then AddSlash := '/' else AddSlash := ''; if LowerCase(URL) = Copy(Location, Pos('?url=', Location) + 5, MaxInt) + AddSlash then begin Result := False; Break; end; end; end; // have to assume its OK cos I can't do much else end else begin Result := False; Break; end; end; grab.Clear; end else begin Result := False; Break; end; end else begin Result := False; Break; end; end; finally grab.Free; sl.Free; end; end; to see if a website exists. Can anyone suggest a better approach? Roy Lambert |