|Subject:||Re: IdHTTP and ftp URL|
|Posted by:||Frank Shearar (frank.shear…@rnid.org.uk)|
|Date:||Tue, 29 Jul 2003|
"Michael Fritz" <firstname.lastname@example.org> wrote in message
> I'm using IdHTTP.Head(URL) to check if an URL is valid. What is the
> equivalent for FTP URLs and what about all the other protocol an internet
> address could hold? E.g news:, https: etc.
> How can I check them for validity?
What exactly do you mean by "valid"? Do you mean that the URL is well-formed
(i.e., conforms to the grammar of a URI), or do you mean that the URL points
to something real?
I would suggest using a TIdURI to check that a URL is well-formed. However,
TIdURI right now doesn't handle schemes like mailto: and news: (any URIs
that don't use "//").
First, TIdURI looks for "://" as the scheme delimiter. That's easy to fix.
You look for ":" and drop the "//" if it's present.
What's much more difficult is that if you construct a URI piece-by-piece
(URI.Path := SomePath; URI.Document := SomeDocument; etc.) then how does
TIdURI know whether to add "//" to the authority or not? The only way to
tell the difference between an opaque_part (as defined in RFC 2396) and a
hier_part is that the latter starts with a "/". It doesn't seem right to
require people to write code like "URI.Host := '//www.nevrona.com';".
Anyway, erm, the answer is you'd have to parse a URI to see if it's
well-formed, so whether you do that by using a TIdURI (which will work for
the hierarchical schemes like http or ftp but not for schemes like telnet or
mailto) or by hand writing a parser isn't important.
I hope I actually said something in the above that's useful! It has a high
IdHTTP and ftp URL posted by Michael Fritz on Tue, 29 Jul 2003