Klipfolio. The KPI Dashboard - Evolved
The KPI Dashboard – Evolved
Contact Us
TRY IT Web & Mobile
Sign In

Creating an HTTP POST Request


Your Klip needs to make a POST request to a server.


To make a POST request, we will use the Engines.HTTP object in Klipfolio Dashboard. First, create a new Engines.HTTPRequest object:

var postRequest = Engines.HTTP.newRequest("<your_url>");
Replace <your_url> with the address of the page where the POST request will be sent. Next, set the method property of the request object:

postRequest.method = "POST";
This means the request will be a POST request instead of a regular GET request. Finally, if any POST data is required, add it to the object with the postdata property:

postRequest.postdata = "<your_post_data>";
POST data is usually in the form of name/value pairs. For instance, if your Klip has two input fields in the Setup window for a login name and password, the POST data could be formed as follows:

postRequest.postdata = "login=" + gUserName.value + "&password=" + gPassword.value;

The POST data that is sent must match the protocol that the server is using. In the example above, different servers might call the login data "user" or "username" instead of "login". The POST data may also need to be URL-encoded depending on the server. URL encoding can be accomplished using the Javascript string manipulation functions, such as replace() and escape(). You can determine the exact protocol the server uses by using a tool such as Ethereal, which allows you to examine HTTP requests that are sent and received.

If necessary, cookies can be sent with the request using the cookies property of the request object:

postRequest.cookies = "<your_cookies>";
Now the request is ready to be sent:

    var data = postRequest.response.data;
    trace("The request could not be sent.");

If the POST request succeeds, the response data can be inspected by looking at the HTTPResponse object which is stored in postRequest.response. The response can be used to create a second HTTP request, or the response data can be passed to Engines.Data.process() for processing.

Please note that HTTP requests can only be done in an onRefresh() event handler.

Leave a Comment

To leave a comment, you must sign in or register (it's free).

Comment Type: