There are a number of parameters and methods pertinent to HTTP objects that are available to process an HTTP Response in a Custom Script within an Action, or in script within a Map event.

Script Parameters/Properties For Responses

Parameter/Property

Description

HTTP.Response.ResponseCode

The numeric response code of the HTTP Response.

Please refer to HTTP Status Codes for more information.

Example:

if (HTTP.Response.ResponseCode = 404) then
LogError('Someone moved the end point!');

Or,

if HTTP.Response.ResponseCode = 200 then
LogInfo('Response code: ' + HTTP.Response.ResponseText)
else
LogError('Error - Response Code: ' + HTTP.Response.ResponseText);

HTTP.Response.ResponseText

The corresponding text that relates to the response code of the HTTP Response.

For a response code of 404, the response text would be Not found.

Example:

LogInfo('The connection was: ' + HTTP.Response.ResponseText);

Or,

if HTTP.Response.ResponseCode = 404 then
begin
// document not found... what do we do ?
...
end
else
LogInfo(HTTP.Response.ResponseText);

HTTP.Response.HeaderCount

The number of headers in the HTTP Response.

Example:

if HTTP.Response.HeaderCount > 0 then
LogInfo('There are headers');

HTTP.Response.HeaderName[n]

The name of header n in the HTTP Response.

Example:

LogInfo('Header 2 is: ' + HTTP.Response.HeaderName[2]);

HTTP.Response.HeaderValue[n]

The value of header n in the HTTP Response.

Example:

LogInfo('Header 3 value: ' + HTTP.Response.HeaderValue[3]);

HTTP.Response.HeaderByIndex[n]

The full header line of header n for the HTTP Response, such as Content-Type: application/xml.

Example:

LogInfo('Header 4: ' + HTTP.Response.HeaderByIndex[4]);

HTTP.Response.Header[name]

The value of the named header in the HTTP Response.

Example:

if HTTP.Response.Header['Content-Type'] = 'text/html' then
LogInfo('We got a HTML response!');

Or,

if HTTP.Response.Header['Content-Type'] <> 'application/json' then
begin
LogError('Wrong Content-Type returned: '
+ HTTP.Response.Header['Content-Type']);
Exit;
end;

HTTP.Response.Content.Size

The size of the message body in the HTTP Response in bytes.

Example:

responseSize := HTTP.Response.Content.Size;
LogInfo('Message Body: ' + IntToStr(responseSize) + ' bytes');

You need to allocate space for the response in response_data. If you don’t allocate space for the response, the read will fail when the response is longer than 80 characters.

Example:

Setlength(response_data, HTTP.response.content.size);
HTTP.response.content.read(response_data, HTTP.response.content.size);

HTTP.Response.ContentAsString

Allows a string value to be assigned directly to the HTTP message body response,

Example:

vHTTPResponseBodyStr := '';
vHTTPResponseBodyStr := HTTP.Response.ContentAsString;

Script Methods For Responses

Method

Description

HTTP.Response.Content.Read(response_data, size)

Read a size amount of the response into response_data. If you don’t allocate space for the response, the read will fail when the response is longer than 80 characters.

This could be the whole response, or just part of it.

Example:

size := HTTP.Response.Content.Size;
SetLength(response_data, size);
HTTP.Response.Content.Read(response_data, size);

Each time you read from the content, that amount is removed from the content stream.

This means that you could read the content stream in blocks, you just specify how much you want each time.

Example:

contentSize := HTTP.Response.Content.Size;
SetLength(responseContent, contentSize);
HTTP.Response.Content.Read(responseContent, contentSize);

Or,

size := HTTP.Response.Content.Size;
SetLength(responde_data, 100);
for x := 1 to (size div 100) do
begin
HTTP.Response.Content.Read(response_data, 100);
LogInfo(response_data);
end;

HTTP.Response.Content

Example: