The PARSE_URL function breaks a URL string into substrings that correspond to the URL_* properties of IDLnet* objects.
Note: This is not an object method and does not set any object properties.
Note: If a port number is not found in the URL string parameter, the default port value is 80.
PARSE_URL is a pure string-processing routine. Validation of the values is left to the user. The returned value is a structure created by applying the following rules to the input URL string:
URL Index |
URL Section
|
Example |
Rule |
0 |
Scheme |
“http”, “https”, or “ftp”
|
From beginning of URL string up to (but not including) “://”
|
1 |
Username |
anonymous |
If ‘@’ is present before the first single ‘/’, everything from “://” to either ‘:’ or ‘@’ if ‘:’ is not present
|
2 |
Password |
make-something-up
|
If both ‘@’ and ‘:’ are present before the first single ‘/’, everything from ‘:’ to ‘@’
|
3 |
Host |
somehost.com |
Everything from “://” or ‘@’ to ‘:’ or first single ‘/’
|
4 |
Port |
80 |
If ‘:’ follows the host name, everything between ‘:’ and the first single ‘/’
|
5 |
Path |
directory/subdirectory/index.html
|
Everything between the first single ‘/’ and ‘?’ or end of string
|
6 |
Query |
parm1=value1&parm2=value2
|
Everything from ‘?’ to the end of the string
|
URL string components are illustrated in the following example:
http://uname:passwd@somehost.com:80/path/page.pl?p1=v1&p2=v2
| 0 | | 1 | | 2 | | 3 ||4| 5 | | 6 |
This routine is written in the IDL language. Its source code can be found in the file parse_url.pro in the lib subdirectory of the IDL distribution.
Examples
The following example strips a known URL to its component strings.
urlString = 'http://someserver.com/path/to/firstfile.dat'
PRINT, 'Original URL string = '+urlString
urlComponents = PARSE_URL(urlString)
urlObj =OBJ_NEW('IDLnetURL')
urlObj->SetProperty, URL_SCHEME = urlComponents.scheme, $
URL_HOST = urlComponents.host, $
URL_PATH = urlComponents.path
urlObj->GetProperty, URL_SCHEME = urlScheme
urlObj->GetProperty, URL_HOST = urlHost
urlObj->GetProperty, URL_PATH = urlPath
PRINT, 'URL scheme = '+urlScheme
PRINT, 'URL host = '+ urlHost
PRINT, 'URL path = '+urlPath
Syntax
Result = PARSE_URL(URL)
Return Value
PARSE_URL returns an anonymous structure containing the disassembled segments of the URL. The fields in the structure are:
SCHEME
USERNAME
PASSWORD
HOST
PORT
PATH
QUERY
All fields contain string values.
To see the structure tag names, enter the following code in the IDL command line:
help, Result, /struct
Arguments
URL
A URL in string form.
Keywords
None.
Version History
See Also
IDLnetURL