Issue #00005427

New WGA.HttpClient(url) utility

We already have an http client object that can be retieved via WGA.createHttpClient(). This object is described here.

However it is very complicated to use this from TMLScript.

We now added a wrapper around this http-client to make it more easy to use.

Create the new http client object via

var client = WGA.HttpClient(url)

Available methods on this object are

  • get([callback])
  • delete([callback])
  • post(data [, contenttype[, charset]][, callback])
  • put(data [, contenttype[, charset]][, callback])

For put/post the default contenttype is "text/plain" and default charset is the configured OpenWGA output encoding (normally UTF-8).

The return value of get/delete/post/put is the HTTP-Status code as integer.

In addition we implemented:

  • setRequestHeader(key, value)
  • setRequestHeaders(map)
  • setCredentials(username, password)

setRequestHeader/s() and setCredentials() returns the client object so the methods can be chained with other methods.

get/delete/post/put accepts an optional callback function to read the received data. This callback function is called with a Result object with the following properties:

  • status (the http status code)
  • statusText (status code as text info)
  • text (the result as String)
  • inputStream (an inputstream to read the result as binary data).
  • contentType (the content type of the result)
  • getHeader(headername) - returns a defined response header value


// a simple get request
        console.log("result is", result.text);
    else console.error("HTTP Error", result.statusText)

// a simple post request
    .setCredentials("walter", "wichtig")
        "User-Agent": "Walters HTTPClient/1.0"
    .post("Hallo Düsseldorf", "text/plain", "latin1")