HTTP2 – Block for generating HTTP GET or POST requests

Block SymbolLicensing group: ADVANCED
PIC

Function Description
The HTTP block performs a single shot HTTP request. Target address (URL) is defined by url parameter and urldata input. A final URL is formed in the way so that urldata input is appended to the url parameter. The header input can be used for declaration of additional header fields.

A HTTP request is started by the TRG input. Then the BUSY output is set until the request is finished, which is signaled by a pulse at the DONE output. In case of an error, the pulse is generated at the ERROR output. The errId output carries information about the last error identified by REXYGEN system error code. The hterror carries a HTTP status code. All data received from server is published via the data output. All error outputs are reset when a new HTTP request is triggered by the TRG input.

The block may be run in blocking or non-blocking mode which is specified by the BLOCKING parameter. In blocking mode, execution of a task is suspended until the request is finished. In non-blocking mode, the block performs only single operation depending on available data and execution of a task is not blocked. It is advised to always run HTTP block in non-blocking mode. It is however necessary to mention that on various operating systems some operations cannot be performed in the non-blocking mode, so be careful and do not use this block in quick tasks (QTASK) or in tasks with short execution period. The non-blocking operation is best supported on GNU/Linux operating system. The maximal duration of a request performed by the HTTP block is specified by the timeout parameter.

The block supports user authentication using basic HTTP authentication method. User name and password may be specified by user and password parameters. The block also supports secure HTTP (HTTPS). It is also possible to let the block verify server’s certificate by setting the VERIFY parameter. SSL certificate of a server or server’s trusted certificate authority must be stored in the certificate parameter in a PEM format. The block does not support any certificate storage.

Parameters postmime and acceptmime specify MIME encoding of data being sent to server and expected encoding of the HTTP response.

Parameters nmax, postmax, and datamax specify maximum sizes of buffers allocated by the block. The nmax parameter is maximal size of any string parameter. The postmax parameter specifies a maximal size of postdata. The datamax parameter specifies a maximal size of data.

Inputs

postdata

Data to put in HTTP POST request

String

urldata

Data to append to URL address

String

header

Additional header fields

String

TRG

Trigger of the selected action

Bool

Parameters

url

URL address to send the HTTP request to

String

method

HTTP request type  1

Long (I32)

1 ....

GET

2 ....

POST

3 ....

PUT

4 ....

DELETE

5 ....

HEAD

6 ....

TRACE

7 ....

PATCH

8 ....

OPTIONS

9 ....

CONNECT

user

User name

String

password

Password

String

certificate

Authentication certificate

String

VERIFY

Enable server verification (valid certificate)

Bool

postmime

MIME encoding for POST request  application/json

String

acceptmime

MIME encoding for GET request  application/json

String

timeout

Timeout interval  5.0

Double (F64)

BLOCKING

Wait for the operation to finish

Bool

nmax

Allocated size of string   0  65520

Long (I32)

postmax

Allocated memory for POST request data   128  65520 4096

Long (I32)

datamax

Allocated memory for HTTP response   128  10000000 64000

Long (I32)

Outputs

data

Response data

String

BUSY

Sending HTTP request

Bool

DONE

HTTP request processed

Bool

ERROR

Error indicator

Bool

errId

Error code

Error

hterror

HTTP response

Long (I32)

2023 © REX Controls s.r.o., www.rexygen.com