HTTP Query

To provide this example, the basics of HTTP are first explained. This is important to understand the functionality of the interface.

Basics

The following points should be noted:

  • A request via HTTP establishes a connection from the client until the server terminates the connection.
  • The query is made via TCP over port 80 (unencrypted HTTP) and over port 443 (encrypted HTTPS).
  • If port 80 is used with http:// or port 443 with https://, the port is hidden.
  • From HTTP/1.1 onwards, the connection layer is such that the connection is left open for a while to avoid the TCP handshake. This is not visible in the Antcas monitor. However, after the timeout, the connection from the client, i.e., the Antcas server, is closed. The timeout should therefore be set accordingly high.
  • Every query is fully backward compatible. Whether a server supports HTTP/1.0, HTTP/1.1, or HTTP/2 does not matter in this case.
  • The header is case-insensitive. This means that uppercase and lowercase letters do not matter. However, there are some manufacturers who do not pay attention to implementing this accordingly.
  • The character encoding in Antcas Control is always UTF-8. If others are used, these must be converted if necessary.
  • The maximum length of a URL including query is 2'083 characters.

The structure of a URL looks like this:

http://server.tld/getdata?project=you%26i+project&id=25#anker
Component Meaning
http:// Defines the protocol. Antcas Control currently supports http and https.
server.tld Defines the domain (DNS) or IP address of the target server.
getdata Is the URI of the server. This corresponds to the target page, comparable to a path.
?[...] The ? separates the URL from the so-called GET request, followed by all form data also called query. The query is always encoded to replace unsupported characters.
#[...] The #-sign defines an anchor on a page. This allows jumping (scrolling) to any location. These data are not transmitted to the server. In addition, this area including # must not be copied into the query, as this would otherwise call another target page on the server.

The configuration of the target servers is done in the corresponding HTTP gateway.

Structure Of A Query

The structure of a query consists of a header and a body. The header always shows the method used, the URI, and the protocol in the first line.

GET /getdata?project=you%26i+project&id=25 HTTP/1.1
Host: server.tld

This is followed by the server's response. This includes the status code of the query. The body follows the header with an empty line.

HTTP/1.1 200 OK
Server: Apache2
Content-Type: text/html

<html>Hello World</html>

Status Codes

The status codes are divided into groups. The groups are defined by the first digit. In addition, after the number comes the meaning in plain text. Here are some examples:

Status Description
200 OK The request was successful.
301 Found Redirection to the actual page. Since Antcas Control follows links, this response is usually hidden.
404 Not Found The specified page was not found.
500 Internal Server Error A server error has occurred.

Methods

The GET and POST methods are used most frequently.

Method Description
GET The GET query is the standard query. This does not support any content.
POST The POST query sends content to the server. The content can also be empty. The advantage here is that the content has no length restriction. With a GET request, only a certain number of data can be transmitted.
PUT PUT is used by interfaces to exchange information.
DELETE Together with PUT, it is used to delete data.
(others) Other HTTP methods are also supported but require appropriate configuration.

Authentication

Most authentications take place in the header. However, there are also requests that are defined in the query or content.

It may be necessary to create a session before the actual request. The session is then set as a header Set-Cookie. This cookie must then be passed again. The contents of the cookies are case-sensitive, meaning the contents must be passed one-to-one. Here is a simplified example:

POST /login HTTP/1.1
Host: server.tld

username=myname&password=1234

Server response:

HTTP/1.1 200 OK
Server: Apache2
Content-Type: text/html
Set-Cookie: SESSION=vmvbquk7dq6dbbcq

Now the cookie can be used again in the next query:

GET /opendoor HTTP/1.1
Host: server.tld
Cookie: SESSION=vmvbquk7dq6dbbcq

Tips

In the browser's developer console, the request can be evaluated and tested under Network. In addition, it is sometimes advisable to copy or view the header.

Configuration

In Antcas Control, an HTTP interface with a gateway is created. The gateway is configured as an HTTP client. Here, the target address and port (required) are entered accordingly. Then, in the structure, the query is configured. For this purpose, the URL is entered as a variable under Communication.

Simple Query

To create a simple query, any data type is selected. This is preferably a string. If a value change occurs at the output, a query is already executed. The value is then used directly as a query.

Complex Query

A more complex query is created using the function block HTTP_REQUEST. For this purpose, the data type of communication must be set to raw. The response can then be evaluated using the function block HTTP_RESPONSE. The ID of the query must be linked for this purpose in order to correctly assign the response to the request.

Example

In this example, data is sent to a server using the GET method and the response is evaluated. The complete URL is as follows:

http://server.tld/getdata?project=you%26i+project&id=25

To retrieve or send data from/to a server, the following example is used:

Note: The example does not show how the request must be triggered. This is triggered with a positive edge at the input SET. To prevent an unwanted query, the input DIS should be set to TRUE.

The configuration of the interface is configured as follows: