Class HTTP
java.lang.Object
org.openhab.core.model.script.actions.HTTP
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 Summary
Modifier and TypeFieldDescriptionstatic final String
Constant which represents the content typeapplication/json
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
Send out a DELETE-HTTP request.static String
sendHttpDeleteRequest
(String url, int timeout) Send out a DELETE-HTTP request.static String
sendHttpDeleteRequest
(String url, Map<String, String> headers, int timeout) Send out a DELETE-HTTP request.static String
sendHttpGetRequest
(String url) Send out a GET-HTTP request.static String
sendHttpGetRequest
(String url, int timeout) Send out a GET-HTTP request.static String
sendHttpGetRequest
(String url, Map<String, String> headers, int timeout) Send out a GET-HTTP request.static String
Send out a POST-HTTP request.static String
sendHttpPostRequest
(String url, int timeout) Send out a POST-HTTP request.static String
sendHttpPostRequest
(String url, String contentType, String content) Send out a POST-HTTP request.static String
sendHttpPostRequest
(String url, String contentType, String content, int timeout) Send out a POST-HTTP request.static String
sendHttpPostRequest
(String url, String contentType, String content, Map<String, String> headers, int timeout) Send out a POST-HTTP request.static String
sendHttpPutRequest
(String url) Send out a PUT-HTTP request.static String
sendHttpPutRequest
(String url, int timeout) Send out a PUT-HTTP request.static String
sendHttpPutRequest
(String url, String contentType, String content) Send out a PUT-HTTP request.static String
sendHttpPutRequest
(String url, String contentType, String content, int timeout) Send out a PUT-HTTP request.static String
sendHttpPutRequest
(String url, String contentType, String content, Map<String, String> headers, int timeout) Send out a PUT-HTTP request.
-
Field Details
-
CONTENT_TYPE_JSON
Constant which represents the content typeapplication/json
- See Also:
-
-
Constructor Details
-
HTTP
public HTTP()
-
-
Method Details
-
sendHttpGetRequest
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
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
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
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
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
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 givencontent
content
- the content to be send to the givenurl
ornull
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 givencontent
content
- the content to be send to the givenurl
ornull
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 givencontent
content
- the content to be send to the givenurl
ornull
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
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
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
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 givencontent
content
- the content to be send to the givenurl
ornull
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 givencontent
content
- the content to be send to the givenurl
ornull
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 givencontent
content
- the content to be send to the givenurl
ornull
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
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
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
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
-