This method is used to request data from a specified resource without modifying it.
Newlook Smartclient
Newlook Server
Introduced in Version 10.7 (Newlook Server API).
Introduced in Version 11.0 (Scripting support).
HTTP.Get(Url[, Params][, DataType])
The Get method syntax has these parameters:
Part |
Description |
URL |
String expression that specifies the URL of the server-based resource. |
Params |
Optional. A structure of name/value pairs containing the parameters to be passed to the routine. |
DataType |
Optional. DataType Constant specifying how Newlook should interpret the returned content. This method assumes the response will consist of a UTF8 string (regardless of the Content-Type in the response header). The dataType parameter is then used to determine if the content will be parsed as JSON or returned as literal text. If omitted, nlHttpDataTypeAutoDetect is used. |
The available dataType constants:
Constant |
Value |
Description |
nlHttpDataTypeAutoDetect |
0 |
Detect the content type from the response's Content-Type header (default). |
nlHttpDataTypeText |
1 |
Newlook will ignore the Content-Type in the response header and return the content as a string. |
nlHttpDataTypeJson |
2 |
Newlook will ignore the Content-Type in the response header and attempt to convert the returned data to a JSON object. |
In the case where the dataType argument is set to nlHttpDataTypeAutoDetect and we don't detect a JSON payload or the dataType is set to nlHttpDataTypeText, then this method returns a string.
Where a JSON payload is detected, the Get method can return the following types:
If you are using this method in a JScript script and the returned content is an array, you will need to convert the returned value to a JScript array using the VBArray(...).toArray()
method (see second example below).
It is important to note that his method only supports UTF-8 encoded responses (regardless of media type).
The following JScript example uses the Get method to return a record:
// Example return data
// var data =
// {
// serial: "0000-32323-23323",
// registration: "000-000"
// price: 9990
// }
var data = Http.Get("http://localhost/mycars/FindFirst", { make: "saab", model: "9000", year: 1984 });
// update inputs on the active form
App.ActiveForm.labelSerial.Text = data.serial;
App.ActiveForm.labelRego.Text = data.registration;
App.ActiveForm.labelPrice.Text = data.price;
The following JScript example uses the Get method to an instance of a user defined type:
// Example return data
// var data =
// [
// { Id: "P3234", Description: "Spoke", Available: 7000 },
// { Id: "P7534", Description: "Rod", Available: 6000 },
// { Id: "P9533", Description: "Widget", Available: 458 }
// ];
// read inputs from the active form
var varMake = App.ActiveForm.inputMake.Text;
var varModel = App.ActiveForm.inputModel.Text;
var varYear = new Number(App.ActiveForm.inputYear.Text);
var partsArray = Http.Get("http://localhost/mycars/GetParts", { make: varMake, model: varModel, year: varYear });
// No conversion required to store returned value
App.SetValue("vCarParts", partsArray);
// Required to access array data within 'JScript'
var data = new VBArray(partsArray).toArray();
gridParts.Clear()
for (var pos = 0; pos < data.length; pos++)
{
var rowData = data[pos];
if (App.ActiveForm.gridParts.InsertRow(pos))
{
App.ActiveForm.gridParts.Rows(pos).Cells(0).Text = rowData.Id;
App.ActiveForm.gridParts.Rows(pos).Cells(1).Text = rowData.Description;
App.ActiveForm.gridParts.Rows(pos).Cells(2).Text = rowData.Available;
}
}
HTTP object
© 2004-2021 looksoftware. All rights reserved.