I need to be able to break a URL down into different segments. Take this path for example:
http://login:password@somehost.somedomain.com:8080/some_path/something_else.html?param1=val¶m2=val#nose
\__/ \___/ \______/ \_____________________/ \__/\____________________________/ \___________________/ \__/
| | | | | | | |
Scheme Username Password Host Port Path Query Fragment
This should break down as follows:
Protocol: HTTP
Username: login
Password: password
Host: somehost.somedomain.com
Port: 8080
Path Info: /some_path/something_else.html
Query String: param1=val¶m2=val
How can I do this in Delphi? Is there something ready made which can split this up for me? If not, how do I go about parsing all the different possible formats? This is assuming that it might even be a different protocol, such as HTTPS or RTSP.
You can use the
InternetCrackUrl
method.Try this simple
This will return
XE2 ships with Indy, which has a
TIdURI
class for that purpose, eg: