Table of Contents
Web
This object allows you to download data.
Functions
Web
Constructor function.
Syntax
var myObject = new Web(eventsAndOptions);
Arguments
- eventsAndOptions - (object) the events that can be called
- onFinished - (onFinished) called when the data has been downloaded
- onDownloadProgress - (onDownloadProgress) called when the download progresses
- onError - (onError) called when an error has occured
- file - (File or string) the file or filename to use as a destination for the downloaded data, if this is not set the data will be stored into RAM
Example
var myObject = new Web();
var myObject = new Web({ onFinished: function() { Console.print("Finished!"); }, file: "myFile.txt" });
Methods
download
Start downloading.
Syntax
myObject.download(url, options);
myObject.download(url);
Arguments
- url - (string) the url of the resource to download
- options - (object) options
- rawHeaders - (object) raw headers to set
- method - (Method) the method to use (get or post)
- postData - (object) post data to send
- rawData - (string) raw post data to send [Since version 3.11.0]
- query - (object) query items
- user - (string) the username to use if asked
- password - (string) the password to use if asked
Returns
- (Web) this Web
Exceptions
- (OpenFileError) unable to open the destination file
Notes
This method is asynchronous, this means that it will return before the data is downloaded. To know when this is done use the onFinished event or the isDownloading method.
isDownloading
Returns true if the data is still being downloaded.
Syntax
myObject.isDownloading();
Returns
- (boolean) true if the data is still being downloaded
toImage
Returns the downloaded data as an Image.
Syntax
myObject.toImage();
Returns
- (Image) the image
Notes
You cannot use this method if you specified a destination file as no data is kept in memory.
toText
Returns the downloaded data as text.
Syntax
myObject.toText(encoding);
myObject.toText();
Arguments
- encoding - (Encoding) the encoding to use
Returns
- (string) the text
Notes
You cannot use this method if you specified a destination file as no data is kept in memory.
toRawData
Returns the downloaded data as RawData.
Syntax
myObject.toRawData();
Returns
- (RawData) the raw data
Notes
You cannot use this method if you specified a destination file as no data is kept in memory.
cancel
Cancel the download.
Syntax
myObject.cancel();
Returns
- (Web) this Web
Events
onFinished
Called when the data has been downloaded.
Syntax
myObject.onFinished = function() {};
Example
myObject.onFinished = function() { //Event action };
onDownloadProgress
Called when the download progression has changed.
Syntax
myObject.onDownloadProgress = function(bytesReceived, bytesTotal) {};
Arguments
- bytesReceived - (integer) received byte count
- bytesTotal - (integer) total byte count
Example
myObject.onDownloadProgress = function(bytesReceived, bytesTotal) { //Event action };
onError
Called when an error occurs.
Syntax
myObject.onError = function(errorText) {};
Arguments
- errorText - (string) a text describing the error
Example
myObject.onError = function(errorText) { //Event action };
Enumerations
Method
The download method.
Values
- Get: use "get" method (default)
- Post: use "post" method