restClientRequest (Function)

Top  Previous  Next

Architecture:

NX32L

Device support:

ALL

Firmware version:

2.10.00


This function will execute a client request and wait for the response.

If the path parameter is not set, the body of the response will be stored in memory and can be read using the restRespBodyGetString, restRespBodyGetJSON and restRespBodyGetRaw functions.

The maximum response size of a response in memory is 1 MB.

If the path parameter is set, the body content will instead be written to the file. The file will be created even if the request fails, e.g. because it can not find the server. If the request fails because the connection times out or if there is not enough free space for the entire file, the data that was received will still be available in the file.

 

Input:

req : SYSHANDLE

The request to execute.

 

path : STRING

The path to a file to store the response in.

 

iface : SINT (Default 0)

The network interface to use for the request. 0 = Any network, 1 = Mobile network, 2 = LAN network, etc. (See Network).

 

Output:

resp : SYSHANDLE

A handle to the response to the request. Must be freed with restRespFree when no longer needed.

 

 

Returns: INT

>0


- HTTP status code

0


- Not supported

-1


- Invalid request.

-2


- The response can not be created before a different response is freed.

-3


- Failed to execute request.

-7


- Response is too large to fit in memory or on the drive.

-10


- Invalid protocol requested.

-11


- Invalid url requested.

-12


- Failed to connect to server.

-13


- Invalid response received.

-14


- SSL Handshake failed.

-15


- Client certificate error.

-16


- Remote certificate could not be validated.

-17


- Too many redirects.

-18


- Failed to escape parameter or key.

-19


- Failed to add headers.

-20


- Failed to add body content.

-21


- File not found

-22


- Access denied

-23


- Timeout

-24


- Could not resolve host.

-25


- Empty reply, server might have closed the connection.

 

Declaration:

FUNCTION restClientRequest : INT;
VAR_INPUT
  req       : SYSHANDLE;
  path      : STRING;
  iface     : SINT;
  resp      : ACCESS SYSHANDLE;
END_VAR;

 

 

Example:

Please see the "Examples - REST Example"