Web Service

<array> reply = webService(<string> URL)

<array> reply = webService(<string> URL, <string> data)

 

This function allows the user to either get data from a web service, or post data to a web service.  If issuing a HTTP GET request (retrieving a URL, optionally with query parameters) the user only needs to specify the URL parameter. If issuing a HTTP POST request, the user must also specify a string of data which will be posted to the request URL.  In either case, the return value for this function is an array.  The array element reply[0] is the returned response from the web service.  If the Content-Type of the web service response is "application/json", the webRequest function will parse it as JSON and return a JSON array. Otherwise, it will be returned as a string. The array element reply[1] is the HTTP status of the reply.  The array element reply[2] is a boolean indicating if the network communication was successful (and thus the other array elements contain valid values).

Note:  When posting data, if the data to be posted is in JSON form, use JSON.stringify(data) to convert the JSON data into a string.

Examples:

var response = webService("http://www.example.com/page1.php"); // issues a GET request for page1.php from example.com

var response = webService("http://www.example.com/page1.php", "data"); // posts the string "data" to the URL specified

var response = webService("www.example.com", JSON.stringify(data)); // converts the JSON object to a string, then posts the string

Note: "data" is a string of data, in a format specific to the target URL.  Please review documentation for target URL to determine the manner in which to pass data.