Working with HTTP

checkConnection();

Check if there is an Internet connection available: if there is, then returns "true" (a String), otherwise "false".

getWebContent(url,httpMethod,contentType,bodyRequest)

execute the HTTP request. Required parameters:

Argument

Description

url

URI to invoke (e.g. http://host:port/webcontent)

httpMethod

HTTP method to use; allowed values: GET, POST, PUT, DELETE

contentType

optional, can be null; e.g. application/json

bodyRequest

optional, can be null; the body request, expressed as a String

 The return value is a String content.

Example

var url = getBaseURL()+"/executeJs?applicationId=...&appId=...&actionId=...&otherparameters&restfulToken="+getToken();
var json = getWebContent(url,"GET","application/json",null);

getWebContent(url,httpMethod,contentType,bodyRequest,headers)

execute the HTTP request with headers. Required parameters:

Argument

Description

url

URI to invoke (e.g. http://host:port/webcontent)

httpMethod

HTTP method to use; allowed values: GET, POST, PUT, DELETE

contentType

optional, can be null; e.g. application/json

bodyRequest

optional, can be null; the body request, expressed as a String

headers

optional, can be null: the request headers, expressed as a map (a js object)

Example

getWebContent(url,httpMethod,contentType,bodyRequest,headers,callback)

execute the HTTP ASYNC request with headers and callback function. Required parameters:

Argument

Description

url

URI to invoke (e.g. http://host:port/webcontent)

httpMethod

HTTP method to use; allowed values: GET, POST, PUT, DELETE

contentType

optional, can be null; e.g. application/json

bodyRequest

optional, can be null; the body request, expressed as a String

headers

optional, can be null: the request headers, expressed as a map (a js object)

callback

optional, can be null: the name of the callback async function, the input of function is the json response

Example

getWebContentLite(url,httpMethod,contentType,bodyContent,headers, Object timeoutMS)

A lite version of getWebContent, this version not manages cookies, session and not refresh token. Use this function when you have to call a physical device like a WI-FI printer.

Since 6.0.1 version

getWebContentAdvanced(url,httpMethod,contentType,bodyContent,headers, timeoutMS)

Works like getWebContent, but the returns consists of:

  • responseCode

  • headers

  • body

the getWebContent instead returns the body directly, or null in case of responseCode different from 200

Since 6.0.2 version

sendFile(url, filePath, fileName, jsCallback);

Invoke a remote serverto pass a local file using the POST HTTP method and the multi-part content type: a file and a filename will be passed. At the end of the sending process, the jsCallback will be invoked. Required arguments:

In the following example, a predefined Platform web service is invoked: it has been designed to work withHTTP requests having POST methodand multi-part content-type. Moreover, such a web service requires an action id which will be automatically invoked after sending the file. You can use it to process the file in some way and get back a response to the client.

ping(ip, successCallback, errorCallback)

If the ip is available call the successCallback else the errorCallback.

Since 6.0.2

getConnectionData(callback)

Get the connection data and pass it to a callback. This function also save the connection data to server con60.

logConnectionData()

Save the connection data on server con60, this function don't block the user interface.

md5HexDigest(stringToEncode)

Return the string encode with md5

Last updated