HTTPGet (Retrieve from Web)

The HTTPGet function is used to send a request to an HTTP server using the Get method.

Syntax

HTTPGet ( URI, ResponseHeader, TimeOut [optional])

Remarks

The HTTPGet function returns a ClosedLong Data type used when declaring a variable as an integer. value that represents the socket reference used by the datalogger for communication. When the instruction is successful, the value is greater than 100.

HTTPGet supports ClosedHTTP Hypertext Transfer Protocol. A TCP/IP application protocol. and HTTPS. When this function is in the program, ClosedTLS Transport Layer Security. An Internet communication security protocol. is enabled in the datalogger automatically, unless the ClosedURI Uniform Resource Identifier is a constant and the first 5 characters are HTTP:.

By default the datalogger includes the method, requested URI, HTTP version, user agent, and host in its request. The Header parameter can be used to specify additional header information. Many applications will not require additional header information, in which case, the Header parameter can be an empty string. If additional header information is sent with the request, the string needs to be set before sending each request since the server will return header information into the string as well.

If the header in the response from the server specifies “Connection: close”, the connection is closed; otherwise, it is left open. If the connection is left open, this same connection is used when the instance of HTTPGet that opened the connection is executed again.

A PakBus address of 3213 in the Files Manager setting of the datalogger can be used to enumerate/manage files written by HTTPGet.

Parameters

URI (Uniform Resource Identifier)

A string that contains the uniform resource identifier (typically a URL) of the HTTP server to be accessed. A username and password can be passed into a URL using http://username:password@http.server.address.

Type: String or variable formatted as a string

Response

Indicates where the results of the request will be written. The parameter can be a variable or the name of a valid file on the datalogger.

Type: String or variable formatted as a string

Header

A string that indicates the additional header information to include in the request. As a result of the request, the server may return header information that is stored in the string. The Header parameter can be an empty string if no additional header information is required.

In the case that more than one header is required, headers can be separated by & CHR(13) & CHR(10) &. For example:

HTTPPost (https://api.placeholder.com/v1/chat/completions,Query_str,Response,"Content-Type: application/json" & CHR(13) & CHR(10) & "Authorization: Bearer xx-XXXXXX")

Type: String or variable formatted as a string

TimeOut (Response Wait Time)

Specifies a time period, in 0.01 seconds, that the datalogger will wait for input after a connection is made, before considering the attempt failed and incrementing Result. The default TimeOut in the absence of this parameter is 7500 (i.e., 75 seconds).

Type: Constant

More information on the Get method, including URIs and valid header fields can be found on the W3C web site.