FTPClient
FTPFileInfo
HTTPClient
HTTPClientLoggingConfig
HTTPRequestPart
Mail
SFTPClient
SFTPFileInfo
WebDAVClient
WebDAVFileInfo
DID THIS ARTICLE SOLVE YOUR ISSUE?
Let us know so we can improve!
Let us know so we can improve!
The HTTPClient class supports the HTTP methods GET, POST, HEAD, PUT, PATCH, OPTIONS, and DELETE. If a secure connection via HTTPS is established the used server certificate or the signing CAs certificate needs to be imported into the customer key store via Business Manager. Note: when this class is used with sensitive data, be careful in persisting sensitive information.
Key selection for mutual TLS:
1var httpClient = new HTTPClient();
2var message;
3httpClient.open('GET', 'http://www.myinstance.com/feed.xml');
4httpClient.setTimeout(3000);
5httpClient.send();
6if (httpClient.statusCode == 200)
7{
8 message = httpClient.text;
9}
10else
11{
12 // error handling
13 message = "An error occurred with status code "+httpClient.statusCode;
14}| Constant | Description |
|---|---|
The default size for sendAndReceiveToFile() returning a File is 5MB deprecated in favor of MAX_GET_FILE_SIZE | |
| MAX_GET_FILE_SIZE: Number = 209715200 | The maximum permitted size (in bytes) of an HTTP response when calling operations which write the response to file. |
| MAX_GET_MEM_SIZE: Number = 10485760 | The maximum permitted size (in bytes) of an HTTP response when calling operations which store the response in memory. |
| Property | Description |
|---|---|
(read-only) | Returns all response headers as a map containing the name and value of the response header. |
| allowRedirect: Boolean | Determines whether redirect handling is enabled. |
bytes: Bytes (read-only) | Returns the bytes in the message body for HTTP status codes between 200 and 299. |
errorBytes: Bytes (read-only) | Returns the returned message body as bytes for HTTP status code greater or equal to 400. |
errorText: String (read-only) | Returns the returned message body as text for HTTP status code greater or equal to 400. |
| hostNameVerification: Boolean | Determines whether host name verification is enabled. |
| identity: KeyRef | Gets the identity used for mutual TLS (mTLS). |
| loggingConfig: HTTPClientLoggingConfig | Gets the logging configuration for this HTTP client. |
responseHeaders: Map (read-only) | Returns all response headers as a map in which each entry represents an individual header. |
statusCode: Number (read-only) | Returns the status code of the last HTTP operation. |
statusMessage: String (read-only) | Returns the message text of the last HTTP operation. |
text: String (read-only) | Returns the returned message body as text for HTTP status codes between 200 and 299. |
| timeout: Number | Returns the timeout for this client, in milliseconds. |
| Constructor | Description |
|---|---|
| HTTPClient() | Constructs the HTTPClient instance with the default configuration. |
| HTTPClient(Object) | Constructs the HTTPClient instance with the given configuration. |
| Method | Description |
|---|---|
| enableCaching(Number) | Calling this method enables caching for GET requests. |
| Returns all response headers as a map containing the name and value of the response header. | |
| getAllowRedirect() | Determines whether redirect handling is enabled. |
| getBytes() | Returns the bytes in the message body for HTTP status codes between 200 and 299. |
| getErrorBytes() | Returns the returned message body as bytes for HTTP status code greater or equal to 400. |
| getErrorText() | Returns the returned message body as text for HTTP status code greater or equal to 400. |
| getHostNameVerification() | Determines whether host name verification is enabled. |
| getIdentity() | Gets the identity used for mutual TLS (mTLS). |
| getLoggingConfig() | Gets the logging configuration for this HTTP client. |
| getResponseHeader(String) | Returns a specific response header from the last HTTP operation. |
| getResponseHeaders() | Returns all response headers as a map in which each entry represents an individual header. |
| getResponseHeaders(String) | Returns all the values of a response header from the last HTTP operation as a list of strings. |
| getStatusCode() | Returns the status code of the last HTTP operation. |
| getStatusMessage() | Returns the message text of the last HTTP operation. |
| getText() | Returns the returned message body as text for HTTP status codes between 200 and 299. |
| getText(String) | Returns the returned message body as text for HTTP status codes between 200 and 299. |
| getTimeout() | Returns the timeout for this client, in milliseconds. |
| open(String, String) | Opens the specified URL using the specified method. |
| Deprecated method. | |
| open(String, String, String, String) | Opens the specified URL with the in parameter method specified Http method with given credentials [user, password] using HTTP basic authentication. |
| send() | Sends an HTTP request. |
| send(File) | This method performs the actual HTTP communication. |
| send(String) | This method performs the actual HTTP communication. |
| send(String, String) | This method performs the actual HTTP communication. |
| sendAndReceiveToFile(File) | This method performs the actual HTTP communication. |
| sendAndReceiveToFile(String, File) | This method performs the actual HTTP communication. |
| sendAndReceiveToFile(String, String, File) | This method performs the actual HTTP communication. |
| sendBytes(Bytes) | This method performs the actual HTTP communication. |
| sendBytesAndReceiveToFile(Bytes, File) | This method performs the actual HTTP communication. |
| sendMultiPart(HTTPRequestPart[]) | Sends a multipart HTTP request. |
| setAllowRedirect(Boolean) | Sets whether automatic HTTP redirect handling is enabled. |
| setHostNameVerification(Boolean) | Sets whether certificate host name verification is enabled. |
| setIdentity(KeyRef) | Sets the identity (private key) to use when mutual TLS (mTLS) is configured. |
| setLoggingConfig(HTTPClientLoggingConfig) | Sets the logging configuration for this HTTP client. |
| setRequestHeader(String, String) | Sets a request header for the next HTTP operation. |
| setTimeout(Number) | Sets the timeout for connections made with this client to the given number of milliseconds. |
assign, create, create, defineProperties, defineProperty, entries, freeze, fromEntries, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, getPrototypeOf, hasOwnProperty, is, isExtensible, isFrozen, isPrototypeOf, isSealed, keys, preventExtensions, propertyIsEnumerable, seal, setPrototypeOf, toLocaleString, toString, valueOf, values
The default size for sendAndReceiveToFile() returning a File is 5MB deprecated in favor of
MAX_GET_FILE_SIZE
Deprecated:
Use MAX_GET_FILE_SIZE instead.
Warning
The maximum permitted size (in bytes) of an HTTP response when calling operations which write the response to file. (200MB)
The maximum permitted size (in bytes) of an HTTP response when calling operations which store the response in memory. (10MB)
(read-only)Returns all response headers as a map containing the name and value of the response header.
Deprecated:
Use getResponseHeaders() instead.
Warning
Determines whether redirect handling is enabled.
(read-only)Returns the bytes in the message body for HTTP status codes between 200 and 299.
(read-only)Returns the returned message body as bytes for HTTP status code greater or equal to 400. Error messages are not written to the response file.
(read-only)Returns the returned message body as text for HTTP status code greater or equal to 400. Error messages are not written to the response file.
Determines whether host name verification is enabled.
Gets the identity used for mutual TLS (mTLS).
Gets the logging configuration for this HTTP client.
(read-only)Returns all response headers as a map in which each entry represents an individual header. The key of the entry holds the header name and the entry value holds a list of all header values.
(read-only)Returns the status code of the last HTTP operation.
(read-only)Returns the message text of the last HTTP operation.
(read-only)Returns the returned message body as text for HTTP status codes between 200 and 299.
Returns the timeout for this client, in milliseconds.
Constructs the HTTPClient instance with the default configuration.
Constructs the HTTPClient instance with the given configuration.
There is one supported configuration option. Unknown options are ignored.
| Name | Type | Description |
|---|---|---|
allowHTTP2 |
boolean |
Allow connections over HTTP/2. This will still allow HTTP/1.1 if that is what the remote server supports. It will also cause all request and response headers to be case-insensitive. The default value is false. |
Sample usage:
1var httpClient = new HTTPClient( { allowHTTP2: true } )Parameters:
Calling this method enables caching for GET requests.
It basically means that a response is cached, and before making a request the HTTP client looks into the cache to determine whether the response is already available. Only responses with a status code of 2xx, with a content length, with a size less than 50k, and which are not intended to be immediately written to a file are cached.
The provided parameter defines the TTL (time to live) for the cached content. A value of 0 disables caching. The URL and the username are used as cache keys. The total size of the cacheable content and the number of cached items is limited and automatically managed by the system. Cache control information send by the remote server is ignored. Caching HTTP responses should be done very carefully. It is important to ensure that the response really depends only on the URL and doesn't contain any remote state information or time information which is independent of the URL. It is also important to verify that the application sends exactly the same URL multiple times.
Parameters:
Returns all response headers as a map containing the name and value of the response header.
Returns:
Deprecated:
Use getResponseHeaders() instead.
Warning
Determines whether redirect handling is enabled.
Returns:
Returns the bytes in the message body for HTTP status codes between 200 and 299.
Returns:
Returns the returned message body as bytes for HTTP status code greater or equal to 400. Error messages are not written to the response file.
Returns:
Returns the returned message body as text for HTTP status code greater or equal to 400. Error messages are not written to the response file.
Returns:
Determines whether host name verification is enabled.
Returns:
Gets the identity used for mutual TLS (mTLS).
Returns:
Gets the logging configuration for this HTTP client.
Returns:
Returns a specific response header from the last HTTP operation. The method returns null if the specific header was not returned.
Parameters:
Returns:
Returns all response headers as a map in which each entry represents an individual header. The key of the entry holds the header name and the entry value holds a list of all header values.
Returns:
Returns all the values of a response header from the last HTTP operation as a list of strings. This reflects the
fact that a specific header, e.g. "Set-Cookie", may be set multiple times. In case there is no such
header, the method returns an empty list.
Parameters:
Returns:
Returns the status code of the last HTTP operation.
Returns:
Returns the message text of the last HTTP operation.
Returns:
Returns the returned message body as text for HTTP status codes between 200 and 299.
Returns:
Returns the returned message body as text for HTTP status codes between 200 and 299.
Parameters:
Returns:
Returns the timeout for this client, in milliseconds.
Returns:
Opens the specified URL using the specified method. The following methods are supported: GET, POST, HEAD, PUT, PATCH, OPTIONS, and DELETE
Parameters:
Deprecated method.
Parameters:
Deprecated:
Use open(String, String, String, String) instead.
Warning
Opens the specified URL with the in parameter method specified Http method with given credentials [user, password] using HTTP basic authentication. The following methods are supported: GET, POST, HEAD, PUT, PATCH, OPTIONS, and DELETE
Parameters:
Sends an HTTP request.
This method performs the actual HTTP communication. Sends the file to the HTTP server. The file content is sent as a request body and is sent "as-is" (text or binary).
Parameters:
This method performs the actual HTTP communication. The text is sent as a request body. If the text is null no data will be sent to the HTTP server.
Parameters:
This method performs the actual HTTP communication. The text is sent as a request body. If the text is null no data will be sent to the HTTP server.
Parameters:
This method performs the actual HTTP communication. If the file is null no data will be sent to the HTTP server. If this method is used with a GET then the file parameter will contain the contents retrieved. When using this method with a PUT/POST then the contents of the file parameter will be sent to the server.
Parameters:
Returns:
This method performs the actual HTTP communication. If the text is null no data will be sent to the HTTP server.
Parameters:
Returns:
This method performs the actual HTTP communication. If the text is null no data will be sent to the HTTP server.
Parameters:
Returns:
This method performs the actual HTTP communication. The bytes are sent as a request body. If the bytes are null no data will be sent to the HTTP server.
Parameters:
This method performs the actual HTTP communication. If the body is null no data will be sent to the HTTP server.
Parameters:
Returns:
Throws:
Sends a multipart HTTP request. This method should only be called if the connection to the remote URL was opened with a POST or PATCH method. All other methods will result in an exception being thrown. The request is constructed from the passed array of parts.
Parameters:
Returns:
Sets whether automatic HTTP redirect handling is enabled. The default value is true. Set it to false to disable all redirects.
Parameters:
Sets whether certificate host name verification is enabled. The default value is true. Set it to false to disable host name verification.
Parameters:
Sets the identity (private key) to use when mutual TLS (mTLS) is configured.
If this is not set and mTLS is used then the private key will be chosen from the key store based on the host name. If this is set to a reference named "__NONE__" then no private key will be used even if one is requested by the remote server.
Parameters:
Sets the logging configuration for this HTTP client.
Parameters:
Sets a request header for the next HTTP operation.
Parameters:
Sets the timeout for connections made with this client to the given number of milliseconds. If the given timeout is less than or equal to zero, the timeout is set to a maximum value of 2 or 15 minutes, depending on the context.
This timeout value controls both the "connection timeout" (how long it takes to connect to the remote host) and the "socket timeout" (how long, after connecting, it will wait without any data being read). Therefore, in the worst case scenario, the total time of inactivity could be twice as long as the specified value.
The maximum timeout is 15 minutes when the client is used in a job, and 2 minutes otherwise. The default timeout for a new client is the maximum timeout value.
This method can be called at any time, and will affect the next connection made with this client. It is not possible to set the timeout for an open connection.
You should always set a reasonable timeout (e.g., a few seconds). Allowing connections to run long can result in thread exhaustion.
Parameters: