WebClient Class
This class allows to perform web methods.
Example:
const SERVER = "www.example.com";
const PORT = 80; // for http protocol
this.web = new WebClient();
this.web.open(SERVER, PORT, false, "");
this.web.onError = function(sender)
{
System.messageBox("An error occurred!");
}
this.web.onReceiving = function(sender, received, total)
{
console<<"downloaded " + received + "B.\n";
}
this.web.onReceived = function(sender)
{
// to decode text use:
System.messageBox("received: " + this.data.toString("utf8"));
// to decode image file use:
this super.img = Bitmap.fromBytes(this.data);
app.invalidate();
}
this.web.onCancel = function(sender)
{
System.messageBox("Downloading canceled!");
}
this.web.getData("/getdata/anyscript");
Item Index
Methods
this
(
WebClient
file
Object constructor.
Parameters:
-
file
StringName of archive to create.
Returns:
WebClient: New instance of Zip class, which manages operations with archive
Example:
this.web = new WebClient();
this.web.open(SERVER, PORT, false, "");
this.web.onReceived = function(sender)
{
...
}
this.web.getData("/getdata/anyscript");
cancel
()
This function cancel running operations of WebClient.
getData
(
resource
[responseToFile]
Easy way to get data from server. Data from the server are saved to a file to location set by second parameter.
Parameters:
Example:
this.web = new WebClient();
this.web.open(SERVER, PORT, false, "");
this.web.getData("/getdata/anyscript");
open
(
host
port=80
useSSL=false
[proxy]
Function opens web location for working.
Parameters:
Example:
this.web = new WebClient();
this.web.open(SERVER, PORT, false, "");
postData
(
resource
data
[responseToFile]
Function posts data to the server.
Parameters:
Example:
this.web = new WebClient();
this.web.open(SERVER, PORT, false, "");
web.postData("/import.php", data);
postFile
(
resource
fileToPost
[responseToFile]
Function posts data to the server.
Parameters:
Example:
this.web = new WebClient();
this.web.open(SERVER, PORT, false, "");
web.postData("/import.php", data);
Properties
Events
onCancel
Callback which is called when some web operation is cancelled.
Example:
this.web = new WebClient();
this.web.open(SERVER, PORT, false, "");
this.web.onCancel = function(sender)
{
System.messageBox("Downloading canceled!");
}
this.web.getData("/getdata/anyscript");
onError
Callback which is called when an error appears.
Example:
this.web = new WebClient();
this.web.open(SERVER, PORT, false, "");
this.web.onError = function(sender)
{
System.messageBox("An error occurred!");
}
this.web.getData("/getdata/anyscript");
onReceived
Callback function which is called when new data has been received.
Example:
this.web = new WebClient();
this.web.open(SERVER, PORT, false, "");
this.web.onReceived = function(sender)
{
// to decode text use:
System.messageBox("received: " + this.data.toString("utf8"));
// to decode image file use:
this super.img = Bitmap.fromBytes(this.data);
app.invalidate();
}
this.web.getData("/getdata/anyscript");
onReceiving
Callback function which is called while receiving new data.
Event Payload:
Example:
this.web = new WebClient();
this.web.open(SERVER, PORT, false, "");
this.web.onReceiving = function(sender, received, total)
{
console<<"downloaded " + received + "B.\n";
}
this.web.getData("/getdata/anyscript");
onSending
Callback function which is called while sending data.
Event Payload:
Example:
his.web = new WebClient();
this.web.open(SERVER, PORT, false, "");
this.web.onReceiving = function(sender, received, total)
{
console<<"downloaded " + received + "B.\n";
}
this.web.getData("/getdata/anyscript");