Table of Contents

Web

This object allows you to download data.

Functions

Web

Constructor function.

Syntax

var myObject = new Web(eventsAndOptions);

Arguments

  1. 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

  1. url - (string) the url of the resource to download
  2. 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

Exceptions

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

toImage

Returns the downloaded data as an Image.

Syntax

myObject.toImage();

Returns

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

  1. encoding - (Encoding) the encoding to use

Returns

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

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

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

  1. bytesReceived - (integer) received byte count
  2. 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

  1. errorText - (string) a text describing the error

Example

myObject.onError = function(errorText)
{
	//Event action
};

Enumerations

Method

The download method.

Values

  1. Get: use "get" method (default)
  2. Post: use "post" method