HTTP Client Functions

HTTP Client Functions

The client functions are used to exchange data with a HTTP/HTTPS server. There are specific functions for GET and POST as well as functions for general HTTP requests. Either plain text or encrypted communication can be used. Basic authentication is supported, as well as the use of a keystore, and if required a truststore, for the functions with an encrypted communication channel.

The HTTP client functions also support the use of proxy, see HTTP Proxy Support for information on how to setup HTTP proxy support.

Before using APL functions with TLS/SSL Encryption, refer to configuration required in HTTP Client Functions | TLS/SSL Encryption

The following functions for HTTP Client described here are:

httpGetURL

This function uses the GET method to retrieve content from an HTTP server.

string httpGetURL ( string query, string host, int timeout, int port, //Optional string username, //Optional string password, //Optional map<string, string> headers, //Optional int connectTimeout) //Optional

Parameter

Description

Parameter

Description

query

The query including path

Example - query



/api/v2/doc/1 /api/v2/doc?id=1





host

The name or IP address where the HTTP server is running

timeout

The number of seconds to wait for a response. If the value is set to 0 (zero), the default timeout will be used. The default value is 15 seconds.

port

The port number to contact the HTTP server on. Port 80 is used by default.

username

A username for an account on the HTTP server

password

Password associated with the username

headers

Custom HTTP request headers.

connectTimeout

The number of seconds to wait for a connection to be established. If the value is set to 0 (zero), the default timeout will be used. The default value is 15 seconds.

Returns

Content from the HTTP server. It will be null if any part of the communication fails.

httpBinaryGetURL

This function uses the GET method to retrieve binary content from an HTTP server.

bytearray httpBinaryGetURL ( string query, string host, int timeout, int port, //Optional string username, //Optional string password, //Optional map<string, string> headers, //Optional int connectTimeout) //Optional

Parameter

Description

Parameter

Description

query

The query including path

Example - query

/api/v2/img/1 /api/v2/img?id=1

host

The name or IP address where the HTTP server is running

timeout

The number of seconds to wait for a response. If the value is set to 0 (zero), the default timeout will be used. The default value is 15 seconds.

port

The port number to contact the HTTP server on. Port 80 is used by default.

username

A username for an account on the HTTP server

password

Password associated with the username

headers

Custom HTTP request headers.

connectTimeout

The number of seconds to wait for a connection to be established. If the value is set to 0 (zero), the default timeout will be used. The default value is 15 seconds.

Returns

A bytearray from the HTTP server. It will be null if any part of the communication fails.

httpGetSecureURL

This function uses the GET method to retrieve content from an HTTPS server. The communication channel is encrypted.

string httpGetSecureURL ( string query, string host, int timeout, int port, //Optional string username //Optional string password, //Optional map<string, string> headers, //Optional int connectTimeout) //Optional

Parameter

Description

Parameter

Description

query

The query including path

Example - query

/api/v2/doc/1 /api/v2/doc?id=1

host

The name or IP address where the HTTPS server is running

timeout

The number of seconds to wait for a response. If the value is set to 0 (zero), the default timeout will be used. The default value is 15 seconds.

port

The port number to contact the HTTPS server on. Port 443 is used by default.

username

A username for an account on the HTTP server

password

Password associated with the username

headers

Custom HTTP request headers.

connectTimeout

The number of seconds to wait for a connection to be established. If the value is set to 0 (zero), the default timeout will be used. The default value is 15 seconds.

Returns

Content from the HTTPS server. It will be null if any part of the communication fails.

See the section below, TLS/SSL Encryption.

httpBinaryGetSecureURL

This function uses the GET method to retrieve binary content from an HTTPS server. The communication channel is encrypted.

bytearray httpBinaryGetSecureURL ( string query, string host, int timeout, int port, //Optional string username //Optional string password, //Optional map<string, string> headers, //Optional int connectTimeout) //Optional

Parameter

Description

Parameter

Description

query

The query including path

Example - query

/api/v2/img/1 /api/v2/img?id=1

host

The name or IP address where the HTTPS server is running

timeout

The number of seconds to wait for a response. If the value is set to 0 (zero), the default timeout will be used. The default value is 15 seconds.

port

The port number to contact the HTTPS server on. Port 443 is used by default.

username

A username for an account on the HTTP server

password

Password associated with the username

headers

Custom HTTP request headers.

connectTimeout

The number of seconds to wait for a connection to be established. If the value is set to 0 (zero), the default timeout will be used. The default value is 15 seconds.

Returns

A bytearray from the HTTPS server. It will be null if any part of the communication fails.

See the section below, TLS/SSL Encryption.

httpPostURL

This function uses the POST method to send content to an HTTP server and receives the response.

string httpPostURL ( string path, string contentType, string content, string host, int timeout, int port, //Optional string username, //Optional string password, //Optional map<string, string> headers, //Optional int connectTimeout) //Optional

Parameter

Description

Parameter

Description

path

The path

Example - path

/api/v2/doc

contentType

The MIME type of the content

Example - contentType

/application/json

content

The body of the request

host

The name or IP address where the HTTP server is running

timeout

The number of seconds to wait for a response. If the value is set to 0 (zero), the default timeout will be used. The default value is 15 seconds.

port

The port number to contact the HTTP server on. Port 80 is used by default.

username

A username for an account on the HTTP server

password

Password associated with the username

headers

Custom HTTP request headers.

connectTimeout

The number of seconds to wait for a connection to be established. If the value is set to 0 (zero), the default timeout will be used. The default value is 15 seconds.

Returns

Content from the HTTP server. It will be null if any part of the communication fails.

httpBinaryPostURL

This function uses the POST method to send binary content to an HTTP server and receives the response.

bytearray httpBinaryPostURL ( string path, string contentType, bytearray content, string host, int timeout, int port, //Optional string username, //Optional string password, //Optional map<string, string> headers, //Optional int connectTimeout) //Optional

Parameter

Description

Parameter

Description

path

The path

Example - path

/api/v2/img

e



contentType

The MIME type of the content

Example - contentType

/application/octet-stream

content

The body of the request

host

The name or IP address where the HTTP server is running

timeout

The number of seconds to wait for a response. If the value is set to 0 (zero), the default timeout will be used. Default value is 15 seconds.

port

The port number to contact the HTTP server on. Port 80 is used by default.

username

A username for an account on the HTTP server

password

Password associated with the username

headers

Custom HTTP request headers.

connectTimeout

The number of seconds to wait for a connection to be established. If the value is set to 0 (zero), the default timeout will be used. The default value is 15 seconds.

Returns

A bytearray from the HTTP server. It will be null if any part of the communication fails.

httpPostSecureURL

This function uses the POST method to send content to an HTTPS server and receives the response. The communication channel is encrypted.

string httpPostSecureURL ( string path, string contentType, string content, string host, int timeout, int port, //Optional string username, //Optional string password, //Optional map<string, string> headers, //Optional int connectTimeout) //Optional

Parameter

Description

Parameter

Description

path

The path

Example - path

/api/v2/doc

contentType

The MIME type of the content

Example - contentType

/application/json

content

The body of the request

host

The name or IP address where the HTTPS server is running

timeout

The number of seconds to wait for a response. If the value is set to 0 (zero), the default timeout will be used. Default value is 15 seconds.

port

The port number to contact the HTTPS server on. Port 443 is used by default.

username

A username for an account on the HTTP server

password

Password associated with the username

headers

Custom HTTP request headers.

connectTimeout

The number of seconds to wait for a connection to be established. If the value is set to 0 (zero), the default timeout will be used. The default value is 15 seconds.

Returns

A document from the HTTP server. It will be null if any part of the communication fails.

See the section below, TLS/SSL Encryption.

httpBinaryPostSecureURL

This function uses the POST method to send binary content to an HTTP server and receives the response. The communication channel is encrypted.

bytearray httpBinaryPostSecureURL ( string path, string contentType, bytearray content, string host, int timeout, int port, //Optional string username, //Optional string password, //Optional map<string, string> headers, //Optional int connectTimeout) //Optional

Parameter

Description

Parameter

Description

path

The path

Example - path

/api/v2/img

contentType

The MIME type of the content

Example - contentType

/application/octet-stream

content

The body of the request

host

The name or IP address where the HTTPS server is running

timeout

The number of seconds to wait for a response. If the value is set to 0 (zero), the default timeout will be used. Default value is 15 seconds.

port

The port number to contact the HTTPS server on. Port 443 is used by default.

username

A username for an account on the HTTP server

password

Password associated with the username

headers

Custom HTTP request headers.

connectTimeout

The number of seconds to wait for a connection to be established. If the value is set to 0 (zero), the default timeout will be used. The default value is 15 seconds.

Returns

A bytearray from the HTTP server. It will be null if any part of the communication fails.

See the section below, TLS/SSL Encryption.

httpRequest

This function makes an HTTP request and uses the specified method, e g GET, POST, PUT etc.

string httpRequest ( string method, string url, map<string, string> headers, string path, string content, string contentType, list dynamicArgs) //Opt

Parameter

Description

Parameter

Description

method

The HTTP method

url

The host and port of the HTTP server, e g http://host:port

header

Key-value pairs containing request header fields

path

The path

Example - path

/api

content

The body of the request.

contentType

The MIME type of the content

Example - contentType

/application/json

dynamicArgs

The body of the request

httpRequestBasicAuth

This function makes an HTTP request with basic authentication and uses the specified method, e g GET, POST, PUT etc.

string httpRequestBasicAuth ( string method, string url, map<string,string> header, string contentType, string content, int timeout, string username string password, int connectTimeout) //Optional