restReqHeaderGet (Function)

Top  Previous  Next

Architecture:

NX32L

Device support:

ALL

Firmware version:

2.10.00


This function will read a header field from a request.

 

Input:

req : SYSHANDLE

A handle to the request.

 

name : STRING

The name of the header field to read.

Common fields include "Content-Type", "Accept" and "User-Agent".

 

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.

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

 

 

Returns: INT

1


- Success

0


- Not supported

-1


- Invalid request

-2


- The header was not found

-7


- The value was too large for a string.

 

Declaration:

FUNCTION restReqHeaderGet : 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 header
  rc := restReqHeaderKey(req:=req, idx:=i, name:=name);
  WHILE rc > 0 DO
    // Get value of header
    restReqHeaderGet(req:=req, name:=name, value:=str);
    DebugMsg(message:=" "+name+"="+str);
    i:=i+1;
    // Get name of next header
    rc := restReqHeaderKey(req:=req, idx:=i, name:=name);
  END_WHILE;
  ...
END;
END_PROGRAM;