|
IDL Reference Guide: Procedures and Functions |
|
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 string components are illustrated in the following example:
http://uname:passwd@somehost.com:80/path/page.pl?p1=v1&p2=v2 |1 | | 2 | | 3 | | 4 ||5 | 6 | | 7 |
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.
Result = PARSE_URL(URL)
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
A URL in string form.
None.
The following example strips a known URL to its component strings.
PRO ParseUrlExample
; Start with a hypothetical URL string
urlString = 'http://someserver.com/path/to/firstfile.dat'
PRINT, 'Original URL string = '+urlString
; Split the URL into its component substrings
urlComponents = PARSE_URL(urlString)
; Populate an IDLnetURL object with the URL information
urlObj =OBJ_NEW('IDLnetURL')
urlObj->SetProperty, URL_SCHEME = urlComponents.scheme, $
URL_HOST = urlComponents.host, $
URL_PATH = urlComponents.path
; Get the object's URL property values, and print them
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
END
IDL Online Help (March 06, 2007)