restReqCreate (Function)

Top  Previous  Next

Architecture:

NX32L

Device support:

ALL

Firmware version:

2.10.00


This function will create a new request that can be executed by calling restClientRequest.

To free the request when it is no longer needed, call restReqFree.

This request can both be written and read.

There can maximum be 20 requests at the same time. This includes requests used for the server endpoint callbacks, see restServerEndpointAdd.

 

Input:

method : STRING (default "GET")

The HTTP method to use for the request.

 

url : STRING

The URL of the request, including the protocol ("http://" or "https://").

 

check_server: BOOL (default TRUE)

Set to FALSE to not validate the server certificate when using TLS.

 

check_hostname : BOOL

Set to FALSE to not validate the hostname of the server when using TLS. This is useful if the server uses a dynamic IP address so the server certificate is not able to match the hostname.

 

follow_redirect: BOOL (default FALSE)

Set to TRUE to follow HTTP redirects, which could cause it to receive content that does not match the expected content. By leaving it at FALSE, any redirect response will be returned and can be manually handled.

 

timeout: INT (default 20)

The timeout in seconds before canceling the request.

 

Output:

req : SYSHANDLE

A handle to the new request.

 

 

Returns: INT

1


- Success

0


- Not supported

-2


- The max number of requests have already been created.

-3


- Failed to create request.

 

Declaration:

FUNCTION restReqCreate : INT;
VAR_INPUT
  req            : ACCESS SYSHANDLE;
  method         : STRING := "GET";
  url            : STRING;
  check_server   : BOOL := TRUE;
  check_hostname : BOOL := TRUE;
  timeout        : INT := 20;
  follow_redirect: BOOL;
END_VAR;

 

 

Example:

INCLUDE rtcu.inc
 
PROGRAM example;
VAR
  rc    : INT;
  req   : SYSHANDLE;
END_VAR
BEGIN
 
  rc := restReqCreate(req := req, url := "https://www.example.com");
  ...
  rc := restReqFree(req := req);
END;
END_PROGRAM;