FB_IotHttpRequest

FB_IotHttpRequest 1:

This function block enables the PLC to send HTTP commands to the server that has been configured with the function block FB_IotHttpClient. To be able to process an HTTP response, the output bBusy of this function block must first return FALSE. Then the content payload, specific header fields or a JSON string can be extracted from the response.

Syntax

Definition:

FUNCTION_BLOCK FB_IotHttpRequest IMPLEMENTS ITcIotHttpResponse
VAR_INPUT
    sContentType     : STRING((ParameterList.cSizeOfHttpContentType-1)) :='text/html;charset=UTF-8';
    eCompressionMode : E_IotHttpCompressionMode                         := 'E_IotHttpCompressionMode.NoCompression';
END_VAR
VAR_OUTPUT
    bBusy            : BOOL;
    bError           : BOOL;
    eErrorId         : ETcIotHttpRequestError;
    nStatusCode      : UINT;
    nContentSize     : UDINT;
END_VAR

FB_IotHttpRequest 2: Inputs

Name

Type

Description

sContentType

STRING

Content type of the request, e.g. the initial value "text/html; charset=UTF-8".

eCompressionMode

E_IotHttpCompressionMode

Enumeration of the different compression modes. Further information is provided in the chapter Compression. The list can be found in the Appendix.

FB_IotHttpRequest 3: Outputs

Name

Type

Description

bBusy

BOOL

This output remains TRUE until the function block has executed the command.

bError

BOOL

Becomes TRUE as soon as an error situation occurs.

eErrorId

ETcIotHttpRequestError

Enumeration of status code on transport level e.g. if a certificate validation has failed. The enumeration can be found in the Appendix.

nStatusCode

UINT

HTTP status code send from the server within the response.

nContentSize

UDINT

Size of the content payload.

FB_IotHttpRequest 4: Methods

Name

Description

GetContent

Reads the response from the HTTP server.

GetHeaderField

Reads the value from a specified header field.

GetJsonDomContent

Parses the server response as JSON object.

SendJsonDomRequest

Sends a request to the server as JSON object.

SendRequest

Sends a HTTP command to the server.

SendXmlDomRequest

Sends a request to the server as an XML object.

Requirements

Development environment

Target platform

PLC libraries to include

TwinCAT v3.1.4024.7 or higher

IPC or CX (x86, x64, ARM)

Tc3_IotBase