URL Transactions and Formatting
This section describes how SenseTalk can be used to access resources on the Internet through their URLs. Through this mechanism, SenseTalk can access the contents of files and websites across the Internet and communicate with remote servers using standard protocols.
A number of supporting functions are available to make it easy to convert information between standard URL formats.
Referring to URL Resources in a Script
To refer to a file or other Internet resource accessed through a URL in a script, use the word url
followed by an expression that evaluates to the URL of the file or resource.
The urlString may be a “file:”, “http:”, or “ftp:” type of URL. URLs of type “file:” can be treated as containers — you can store into or change their contents, provided you have write access to the file. If a urlPropertyList is used, it may contain “scheme”, “host”, “path”, “query” and other keys as defined by the makeURL()
function.
When retrieving an http resource from the Internet using this syntax, an http GET operation is used. The urlString or urlPropertyList may include query data to simulate submitting a form. If you use a string, the makeURL()
function can be used to easily construct a string containing a properly formatted query.
If with headers headerPropertyList is specified, headerPropertyList should be a property list containing any custom HTTP headers to be used in accessing that URL. The custom header information is passed along with any standard headers for both GET (when accessing a URL) and POST (when using the post
command) operations.
After accessing a URL, you may check the status of the remote operation by calling the result() function on the next line of the script. This returns the status value of the request if it is less than the minimum level treated as an error (as specified by the URLErrorLevel
global property) or an exception if the status is at that level or greater and the throwExceptionResults
is set to false.
The data retrieved from the URL is interpreted as text according to the current setting of the defaultStringEncoding
global property. Set this property to the correct encoding (often "UTF8") before fetching the URL data.
Syntax:
url urlString {with headers headerPropertyList}
url urlPropertyList {with headers headerPropertyList}
Example:
put url "http://www.somewhere.com/somepage" into htmlContents
put htmlContents into url "file://localhost/localCopy"
Example:
put {scheme:"http", host:"www.apple.com"} into applePage