restReqQueryGet (Function)

Top  Previous  Next

Architecture:

NX32L

Device support:

ALL

Firmware version:

2.10.00


This function will read a query field from a request.

This function is both used to read values specified in the query string, i.e. "/index?id=xx&value=yy" and to read variables extracted from the URL according to the format specified in restServerEndpointAdd.

If a value is specified multiple times, all the values will be provided, separated by commas.

 

Input:

req : SYSHANDLE

A handle to the request.

 

name : STRING

The name of the query field to read.

 

check_case : BOOL (Default FALSE)

If set to TRUE, the name will use case sensitive comparison.

If left at FALSE, the name will use case insensitive comparison.

Note that if the same name is present with different case, only the value for the first matching name will be returned.

 

 

Output:

value : STRING

The value of the field.

 

 

Returns: INT

1


- Success

0


- Not supported

-1


- Invalid request

-2


- The query was not found

-7


- The value was too large for a string.

 

Declaration:

FUNCTION restReqQueryGet : INT;
VAR_INPUT
  req            : SYSHANDLE;
  name           : STRING;
  check_case     : BOOL := FALSE;
  value          : ACCESS STRING;
END_VAR;

 

 

Example:

INCLUDE rtcu.inc
 
PROGRAM example;
VAR
  rc        : INT;
  str, name : STRING;
  i         : INT;
  req       : SYSHANDLE;
END_VAR
BEGIN
  ...
 
  i:=0;
  // Get name of query
  rc := restReqQueryKey(req:=req, idx:=i, name:=name);
  WHILE rc > 0 DO
    // Get value of query
    restReqQueryGet(req:=req, name:=name, value:=str);
    DebugMsg(message:=" "+name+"="+str);
    i:=i+1;
    // Get name of next query
    rc := restReqQueryKey(req:=req, idx:=i, name:=name);
  END_WHILE;
  ...
END;
END_PROGRAM;