Package com.logicaldoc.core.automation

# Class HttpTool

java.lang.Object
com.logicaldoc.core.automation.HttpTool

public class HttpTool extends Object
Utility methods to call URLs

Since:
  9.2
Author:
  Marco Meschieri - LogicalDOC

## Constructor Summary

Constructors
Constructor
Description
`HttpTool()`

## Method Summary

Modifier and Type
Method
Description
`File`
`download(String url, Map<String,String> headers, int timeout)`
Downloads a file from a URL
`File`
`download(String url, Map<String,String> headers, Map<String,org.apache.hc.client5.http.entity.mime.AbstractContentBody> parts, int timeout)`
Downloads a file received in answer to a multipart POST request
`String`
`get(String url, Map<String,String> headers, int timeout)`
Calls the provided URL with an HTTP GET request
`String`
`post(String url, Map<String,String> headers, String entity, int timeout)`
Calls the provided URL with an HTTP POST request
`String`
`postForm(String url, Map<String,String> headers, Map<String,String> fields, int timeout)`
Sends a HTTP POST request containing a urlencoded form
`String`
`postMultipart(String url, Map<String,String> headers, Map<String,org.apache.hc.client5.http.entity.mime.AbstractContentBody> parts, int timeout)`
Sends a HTTP POST with multiple parts

### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### HttpTool

public HttpTool()

## Method Details

### get

public String get(String url, Map<String,String> headers, int timeout)
Calls the provided URL with an HTTP GET request

Parameters:
  `url` - The URL to call
  `headers` - Optional map of headers
  `timeout` - Timeout in seconds
Returns:
  The response body

### download

public File download(String url, Map<String,String> headers, int timeout)
Downloads a file from a URL

Parameters:
  `url` - The URL to call
  `headers` - Optional map of headers
  `timeout` - Timeout in seconds
Returns:
  The downloaded file, this is a temporary file, remember to delete it when done

### post

public String post(String url, Map<String,String> headers, String entity, int timeout)
Calls the provided URL with an HTTP POST request

Parameters:
  `url` - The URL to call
  `headers` - Optional map of headers
  `entity` - Body of the POST request
  `timeout` - Timeout in seconds
Returns:
  The response body

### postForm

public String postForm(String url, Map<String,String> headers, Map<String,String> fields, int timeout)
Sends a HTTP POST request containing a urlencoded form

Parameters:
  `url` - The URL to call
  `headers` - Optional map of headers
  `fields` - The fields of the form
  `timeout` - Timeout in seconds
Returns:
  The response body

### postMultipart

public String postMultipart(String url, Map<String,String> headers, Map<String,org.apache.hc.client5.http.entity.mime.AbstractContentBody> parts, int timeout)
Sends a HTTP POST with multiple parts

Parameters:
  `url` - The URL to call
  `headers` - Optional map of headers
  `parts` - Map of the parts
  `timeout` - Timeout in seconds
Returns:
  The response body

### download

public File download(String url, Map<String,String> headers, Map<String,org.apache.hc.client5.http.entity.mime.AbstractContentBody> parts, int timeout)
Downloads a file received in answer to a multipart POST request

Parameters:
  `url` - The URL to call
  `headers` - Optional map of headers
  `parts` - Map of the parts
  `timeout` - Timeout in seconds
Returns:
  The downloaded file, this is a temporary file, remember to delete it when done