java.lang.Object
org.openhab.core.model.script.actions.HTTP

public class HTTP extends Object
This class provides static methods that can be used in automation rules for sending HTTP requests
Author:
Kai Kreuzer - Initial contribution, Jan N. Klug - add timeout methods
  • Field Details

    • CONTENT_TYPE_JSON

      public static final String CONTENT_TYPE_JSON
      Constant which represents the content type application/json
      See Also:
  • Constructor Details

    • HTTP

      public HTTP()
  • Method Details

    • sendHttpGetRequest

      public static String sendHttpGetRequest(String url)
      Send out a GET-HTTP request. Errors will be logged, success returns response
      Parameters:
      url - the URL to be used for the GET request.
      Returns:
      the response body or NULL when the request went wrong
    • sendHttpGetRequest

      public static String sendHttpGetRequest(String url, int timeout)
      Send out a GET-HTTP request. Errors will be logged, success returns response
      Parameters:
      url - the URL to be used for the GET request.
      timeout - timeout in ms
      Returns:
      the response body or NULL when the request went wrong
    • sendHttpGetRequest

      public static String sendHttpGetRequest(String url, Map<String,String> headers, int timeout)
      Send out a GET-HTTP request. Errors will be logged, returned values just ignored.
      Parameters:
      url - the URL to be used for the GET request.
      headers - the HTTP headers to be sent in the request.
      timeout - timeout in ms
      Returns:
      the response body or NULL when the request went wrong
    • sendHttpPutRequest

      public static String sendHttpPutRequest(String url)
      Send out a PUT-HTTP request. Errors will be logged, returned values just ignored.
      Parameters:
      url - the URL to be used for the PUT request.
      Returns:
      the response body or NULL when the request went wrong
    • sendHttpPutRequest

      public static String sendHttpPutRequest(String url, int timeout)
      Send out a PUT-HTTP request. Errors will be logged, returned values just ignored.
      Parameters:
      url - the URL to be used for the PUT request.
      timeout - timeout in ms
      Returns:
      the response body or NULL when the request went wrong
    • sendHttpPutRequest

      public static String sendHttpPutRequest(String url, String contentType, String content)
      Send out a PUT-HTTP request. Errors will be logged, returned values just ignored.
      Parameters:
      url - the URL to be used for the PUT request.
      contentType - the content type of the given content
      content - the content to be send to the given url or null if no content should be send.
      Returns:
      the response body or NULL when the request went wrong
    • sendHttpPutRequest

      public static String sendHttpPutRequest(String url, String contentType, String content, int timeout)
      Send out a PUT-HTTP request. Errors will be logged, returned values just ignored.
      Parameters:
      url - the URL to be used for the PUT request.
      contentType - the content type of the given content
      content - the content to be send to the given url or null if no content should be send.
      timeout - timeout in ms
      Returns:
      the response body or NULL when the request went wrong
    • sendHttpPutRequest

      public static String sendHttpPutRequest(String url, String contentType, String content, Map<String,String> headers, int timeout)
      Send out a PUT-HTTP request. Errors will be logged, returned values just ignored.
      Parameters:
      url - the URL to be used for the PUT request.
      contentType - the content type of the given content
      content - the content to be send to the given url or null if no content should be sent.
      headers - the HTTP headers to be sent in the request.
      timeout - timeout in ms
      Returns:
      the response body or NULL when the request went wrong
    • sendHttpPostRequest

      public static String sendHttpPostRequest(String url)
      Send out a POST-HTTP request. Errors will be logged, returned values just ignored.
      Parameters:
      url - the URL to be used for the POST request.
      Returns:
      the response body or NULL when the request went wrong
    • sendHttpPostRequest

      public static String sendHttpPostRequest(String url, int timeout)
      Send out a POST-HTTP request. Errors will be logged, returned values just ignored.
      Parameters:
      url - the URL to be used for the POST request.
      timeout - timeout in ms
      Returns:
      the response body or NULL when the request went wrong
    • sendHttpPostRequest

      public static String sendHttpPostRequest(String url, String contentType, String content)
      Send out a POST-HTTP request. Errors will be logged, returned values just ignored.
      Parameters:
      url - the URL to be used for the POST request.
      contentType - the content type of the given content
      content - the content to be send to the given url or null if no content should be send.
      Returns:
      the response body or NULL when the request went wrong
    • sendHttpPostRequest

      public static String sendHttpPostRequest(String url, String contentType, String content, int timeout)
      Send out a POST-HTTP request. Errors will be logged, returned values just ignored.
      Parameters:
      url - the URL to be used for the POST request.
      contentType - the content type of the given content
      content - the content to be send to the given url or null if no content should be send.
      timeout - timeout in ms
      Returns:
      the response body or NULL when the request went wrong
    • sendHttpPostRequest

      public static String sendHttpPostRequest(String url, String contentType, String content, Map<String,String> headers, int timeout)
      Send out a POST-HTTP request. Errors will be logged, returned values just ignored.
      Parameters:
      url - the URL to be used for the GET request.
      contentType - the content type of the given content
      content - the content to be send to the given url or null if no content should be sent.
      headers - the HTTP headers to be sent in the request.
      timeout - timeout in ms
      Returns:
      the response body or NULL when the request went wrong
    • sendHttpDeleteRequest

      public static String sendHttpDeleteRequest(String url)
      Send out a DELETE-HTTP request. Errors will be logged, returned values just ignored.
      Parameters:
      url - the URL to be used for the DELETE request.
      Returns:
      the response body or NULL when the request went wrong
    • sendHttpDeleteRequest

      public static String sendHttpDeleteRequest(String url, int timeout)
      Send out a DELETE-HTTP request. Errors will be logged, returned values just ignored.
      Parameters:
      url - the URL to be used for the DELETE request.
      timeout - timeout in ms
      Returns:
      the response body or NULL when the request went wrong
    • sendHttpDeleteRequest

      public static String sendHttpDeleteRequest(String url, Map<String,String> headers, int timeout)
      Send out a DELETE-HTTP request. Errors will be logged, returned values just ignored.
      Parameters:
      url - the URL to be used for the DELETE request.
      headers - the HTTP headers to be sent in the request.
      timeout - timeout in ms
      Returns:
      the response body or NULL when the request went wrong