Post - Method

Overview

Type:

Method

Available as of:

V1.0.0.0

Task

The method Post initiates the HTTP method to submit the data to be processed to the specified resource.

Functional Description

By using the inputs i_sHost (mandatory) and i_sResource the default header of the HTTP request is created. If additional information must be added to the header, they must be passed through the input i_anyAdditionalHeader. Data assigned to this input is not verified. At the input i_anyResponseBuffer, you must assign a buffer of sufficient size for storing the entire response received from the server.

The inputs i_anyContent and i_udiContentLength specify the content to be submitted.

The return value of the method is of type BOOL and indicates whether the execution of the method was successful (TRUE) or not (FALSE). Evaluate the diagnostic outputs of the method, in case the return value is FALSE. An error indicated by these outputs needs no reset. The property State must be used to obtain the status of processing.

A call of the method Post is allowed only in state Connected.

Implementation Example

Following example shows how the HTTP request looks like after calling the method Post.

Method call:

sAdditionalHeader := 'Content-Type: application/json$r$nConnection: Keep-Alive';
sContent := 'This is the content!';

fbHTTP.Post(    i_sRessource:= 'example',
                i_sHost:= 'se.com',
                i_anyAdditionalHeader:= sAdditionalHeader,
                i_anyContent:= sContent,
                i_udiContentLength:= 20, 
                i_anyResponseBuffer:= sResponse);

Resulting HTTP request:

POST /example HTTP/1.1
Host: se.com
Content-Length: 20
Content-Type: application/json
Connection: Keep-Alive

This is the content!

State Transition of the Client

Stage

Description

1

Initial state: Connected

2

Function call

3

State: SendingRequest, otherwise an error is detected

4

Final state: ResponseAvailable, otherwise an error is detected

NOTE: In case of online modifications while the function block is processing a Post request, the execution is aborted to prevent a possible access violation caused by processing erroneous pointer addresses.

Interface

Input

Data type

Description

i_sResource

STRING[GPL.Gc_uiMaxLengthOfResource]

Specifies the resource on the host which is to be reached by the request.

i_sHost

STRING[GPL.Gc_uiMaxHostSize]

Specifies the address of the host, and if required, extended by the port.

i_anyAdditionalHeader

ANY_STRING

Specifies additional headers to be added to the HTTP request.

i_anyContent

ANY

Assigns the buffer containing the content to be submitted with the HTTP request.

i_udiContentLength

UDINT

Length of the content in bytes.

i_anyResponseBuffer

ANY

Buffer for storing the response from the server.

Output

Data type

Description

q_xError

BOOL

If this output is set to TRUE, an error has been detected. For details, refer to q_etResult and q_etResultMsg.

q_etResult

ET_Result

Provides diagnostic and status information as a numeric value.

q_sResultMsg

STRING[80]

Provides additional diagnostic and status information as a text message.