ParseURL function
Internet utilities
Return to Introduction  Previous page  Next page
Unit
acInet  

Declaration
function ParseURL(URL: Stringvar Protocol, HostName, URLPath,  
  Username, Password, ExtraInfo: Stringvar Port: Word): Boolean;  

Description
The ParseURL procedure divides the URL string (in) to Protocol, HostName, URLPath (path and file name), Username, Password, ExtraInfo (GET query) and PortNumber values.  
 
The URL location should be specified in following form:  
[protocol://][username:password@]hostname[[:port]/urlpath][?extra]  
examples:  
   http://www.appcontrols.com/download/diskcontrols_trial.exe  
   utilmind.com:80  
   https://secure.element5.com/register.html?productid=140005  
   file://c:/windows/desktop/page.html  
   http://hello:world@www.utilmind.com/locked/topsecret.zip  
 
tip If port was not specified in the URL line, the PortNumber value will be recognized automatically. Defaults ports is 80 for HTTP protocol (or if protocol was not specified in the URL), 443 for HTTPS, 21 is default for FTP and 70 for Gopher.  

Example 1
ParseURL('https://secure.element5.com/register.html?productid=140005', Protocol, HostName, URLPath, ExtraInfo, PortNumber);  
{ Results:  
    Protocol = "https"  
    HostName = "secure.element5.com"  
    URLPath = "/register.html"  
    ExtraInfo = "?productid=140005"  
    PortNumber = 443 (default port for secure (SSL) connection )  
}  

Example 2

ParseURL('utilmind.com', Protocol, HostName, URLPath, ExtraInfo, PortNumber);  
{ Results:  
    Protocol = "http"  
    HostName = "utilmind.com"  
    URLPath = ""  
    ExtraInfo = ""  
    PortNumber = 80 (default port for HTTP protocol)  
}  

Example 3

ParseURL('hello:world@www.utilmind.com/cgi-bin/locked/test.cgi?test', Protocol, HostName, URLPath, ExtraInfo, PortNumber);  
{ Results:  
    Protocol = "http"  
    HostName = "www.utilmind.com"  
    URLPath = "/cgi-bin/locked/test.cgi"  
    ExtraInfo = "?test"  
    PortNumber = 80  
}  

Example 4
ParseURL('file://c:/windows/desktop/page.html', Protocol, HostName, URLPath, ExtraInfo, PortNumber);  
{ Results:  
    Protocol = "file"  
    HostName = ""  
    URLPath = "c:\windows\desktop\page.html"  
    ExtraInfo = ""  
    PortNumber = 0 (local file)  
}  

See also
acHTTP component.