OpenWGA 7.7 - TMLScript reference

WGA
Object:

WGA.HttpClient(url)

Description

Creates an object to do HTTP requests to the specified URL.

The returned object has methods get(), put(), post() and delete() to do the basic http requests to the specified URL.

The read the response from the server those methods have to be called with a callback function as parameter. This callback is then called with a HttpResult object as parameter.

WGA.HttpClient() is available since version 7.7.2

Retrieval WGA.HttpClient(url)
Allowed in script types
  • WebTML pages and normal WebTML actions
  • Master actions
  • TMLScript tasks in jobs
  • Content type events
Properties and methods
Name Purpose
delete([callback]) Sends a DELETE Request to the URL specified in HttpClient object
get([callback]) Sends a GET Request to the URL specified in HttpClient object
post(data [, contenttype [, charset]][, callback]) Sends a POST Request to the URL specified in HttpClient object
put(data [, contenttype [, charset]][, callback]) Sends a PUT Request to the URL specified in HttpClient object
setCredentials(username, password) Sets authorization http-header to the specified value.
setRequestHeader(key, value) Sets a request header to the specified value.
setRequestHeaders(map) Sets request headers to the specified values.
Examples
// a simple get request
WGA.HttpClient("http://some-domain.com").get(function(result){
        if(result.status==200)
	console.log("result is", result.text);
    else console.error("HTTP Error", result.status)
})
// a simple post request WGA.HttpClient("http://some-domain.com") .setCredentials("walter", "wichtig") .setRequestHeaders({ "User-Agent": "Walters HTTPClient/1.0" }) .post("Hallo Düsseldorf", "text/plain", "latin1")