Autor Beitrag
G-man
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 258

Win 2000, Win ME, SuSE 8.2
D5 Standard, D6 Professional
BeitragVerfasst: Di 03.06.03 11:58 
Hallo,
wie kann ich herausfinden ob die URL (aus einem Editfeld) korrekt ist
und falls nicht nach ähnlichen suchen?

G-man

_________________
...To err is human, but to really foul things up requires a computer.
maxk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1696
Erhaltene Danke: 1

Win XP, Debian Lenny
Delphi 6 Personal
BeitragVerfasst: Di 03.06.03 20:23 
1. Nach nicht zulässigen Zeichen suchen und durch %ASCII% ersetzen
2. auf HTTP://, FTP://, GOTHER://, etc. prüfen
3. URL aufrufen und auf Serverantwort 200 warten

_________________
Ein Computer wird das tun, was Du programmierst - nicht das, was Du willst.
tommie-lie
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 4373

Ubuntu 7.10 "Gutsy Gibbon"

BeitragVerfasst: Di 03.06.03 20:29 
Das Protokoll heißt Gopher und nicht Gother.
Aber ich wüsste nicht, wo dsa heute noch eingesetzt wird, bzw heute noch ein Gopher-Server Anfragen beantwortet. Viel wichtiger wäre HTTPS und FTPS.

_________________
Your computer is designed to become slower and more unreliable over time, so you have to upgrade. But if you'd like some false hope, I can tell you how to defragment your disk. - Dilbert
Tweafis
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 647

WinXP + fbsd
Delphi 5 Prof
BeitragVerfasst: Di 03.06.03 22:24 
Err, der Code geht doch nicht...

Fis

_________________
.: Es wird der Tag kommen, an dem wir es nicht mehr ändern können :.
G-man Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 258

Win 2000, Win ME, SuSE 8.2
D5 Standard, D6 Professional
BeitragVerfasst: Mi 04.06.03 11:58 
Jo,
Gibt`s da irgendwo ein Codebeispiel?
Wenn ja, wo?

G-man

_________________
...To err is human, but to really foul things up requires a computer.
MaxiTB
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 679

Win2000, WinXp, Workbench ;-)
D7 Ent, VS2003 Arch.
BeitragVerfasst: Mi 04.06.03 12:23 
Titel: Moment mal ...
Das sind alles nur Alibi-Tests - am besten ists, wenn man auf die Files zugreift und einen Fehler abfängt.

Auf diese weise weiß man 100%ig, ob a) die URL gültig ist und b) die URL wirklich gültig ist (und kein broken link).

_________________
Euer Mäxchen
Wer früher stirbt, ist länger tot.
G-man Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 258

Win 2000, Win ME, SuSE 8.2
D5 Standard, D6 Professional
BeitragVerfasst: Fr 06.06.03 12:03 
Irgendwie so hab ich mir das ja schon gedacht,
aber ich weiß halt nicht, wie ich das in Object Pascal ausdrücken soll...
Wenn`s jemand weiß, bitte posten...

_________________
...To err is human, but to really foul things up requires a computer.
focus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 187

XP, 2k, 98, Me
D6 Prof
BeitragVerfasst: Fr 06.06.03 13:05 
ohne dir zu nahe treten zu wollen willst du von uns hilfestellung oder lösungen?
gruss
michael
focus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 187

XP, 2k, 98, Me
D6 Prof
BeitragVerfasst: Fr 06.06.03 13:17 
habe noch was gefunden was dir mit sicherheit weiterhilft auch wenn ich es nicht gut heisse einfach lösungen zu posten...

ausblenden volle Höhe Delphi-Quelltext
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:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
function GetURLs(line: string): TStringList;
var
  i      : integer;
  posURL,
  s      : string;
begin
   //Obviously, first we create a TStringList.
  Result := TStringList.Create;
   //We must make a copy of our string, since we need a variant section of a string
   //to work with out loop. S is just that. 
  s := line;
   //This is our counter.
  i := 0;
   //If the string is smaller than 5 characters, its not going to be a URL, that is 
   //for sure.
  if Length(s) < 5 then exit;
   //We begin our repeat..unitl loop, using I as the counter of spaces.
   //This is a classic string cracking loop, where a a sentence is broken into its words.
   //Here, we are breaking the string into words, and checking each word in the string
   //if it has any properties that qualify it to be a url.
  repeat
     //Get the first space.
    i := Pos(' ', s);
     //If a space does exist, in fact, then we carve out the possible link.
    if i > 0 then
    begin
       //This is the copy method.
      posURL := Copy(s, 1, i-1);
       //Decrease the s, dynamic string, by whatever we just carved out, so next time 
       //we loop around, we dont have to worry about it. Just use copy to remove the
       //value equivalent to posURL from the main string.
      s := Copy(s, i+1, Length(s)-i);
       //Call the function below, and check if the word is actually a link.
      if isURL(posURL) then
          //if the word indeed is a ling, then add it to the string list. 
         Result.Add(posURL);
     //The expressions within this begin..end section do the same as above, but this
     //is called if only one word/token remains in the s string.
    end else
    begin  
      PosURL := s;
      if isURL(posURL) then
         Result.Add(posURL);
      Break;
    end;
   //if s is empty, stop the loop.
  until Length(s) = 0;
   //This little section will free the TStringList if it contains no items, and set it
   //to nil.
  if Result.Count = 0 then
     begin
       Result.Free;
       Result := nil
     end;
end;
{ This function does the actual checking for the token being a URL. }
function IsURL(s: string): Boolean;
var
  i: integer;
begin
   //From the top, make the result false.
  Result := False;
   //Again, if the text of the token is less than 5, its just not going
   //to be a URL.
  if Length(s) < 5 then exit;
   //If the token contains a period at the end, or two periods combined, 
   //its also not going to be a url.
  if (s[Length(s)] = '.')  or (Pos('..', s) > 0then exit;
   //Now we check for bogus characters, Anything between 33 and 126 is valid,
   //Above or below, are not valid url characters.
  for i := 1 to Length(s) do
    if (Ord(s[i]) < 33or (Ord(s[i]) > 126then exit;
   //The next few things check for individual characteristics of various stringd.
  if (Pos('www.',LowerCase(s)) = 1or (Pos('news:', LowerCase(s)) = 1and
     (Length(s) > 6then
  begin
    Result := True;
    Exit;
  end;
  if (Length(s) > 12or (Pos('mailto:', LowerCase(s)) = 1and
     (Pos('@', s) > 1and (Pos('.', s) > 4and (Pos('.', s) > (Pos('@', s) +1)) then
  begin
    Result := True;
    Exit;
  end;
  if (Pos('http:://', LowerCase(s)) > 0or (Pos('ftp://', LowerCase(s)) > 0and
     (Length(s) > 10and (Pos('.', s) > 7then
  begin
    Result := True;
    Exit;
  end;
end;


gruss
michael
G-man Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 258

Win 2000, Win ME, SuSE 8.2
D5 Standard, D6 Professional
BeitragVerfasst: Di 10.06.03 15:54 
Vielen Dank,
das könnte das sein, was ich gesucht habe...

_________________
...To err is human, but to really foul things up requires a computer.