Package ch.k43.util

Klasse KHTTPClient

java.lang.Object
ch.k43.util.KHTTPClient

public class KHTTPClient extends Object
Support basic HTTP or HTTPS client transactions.

Note: The request headers "Date", "User-Agent", "Host" and "Content-Length" are automatically added.

 Example:
 
 HTTPClient httpClient = New HTTPClient();
 if (!httpClient.get("https://google.com")) {
    KLog.error("HTTPS transaction failed - " + httpGet.getLastError());
    ...
 }
 String hostData = httpClient.getResponseDataAsString():
 
  • Konstruktordetails

    • KHTTPClient

      public KHTTPClient()
      Class constructor.
  • Methodendetails

    • delete

      public boolean delete(String argURL, Properties argHeaders)
      Execute HTTP DELETE request.
      Parameter:
      argURL - URL to connect
      argHeaders - Additional HTTP request headers or null
      Gibt zurück:
      True (if HTTP return code 200), else false
      Seit:
      2024.05.22
    • get

      public boolean get(String argURL)
      Execute HTTP GET request.
      Parameter:
      argURL - URL to connect
      Gibt zurück:
      True if HTTP return code is 200, false otherwise
    • get

      public boolean get(String argURL, Properties argHeaders)
      Execute HTTP GET request and set HTTP request headers.
      Parameter:
      argURL - URL to connect
      argHeaders - Additional HTTP request headers or null
      Gibt zurück:
      True if HTTP return code is 200 else false
    • getLastError

      public String getLastError()
      Return last error message.
      Gibt zurück:
      Last error message or null
    • getResponseCode

      public int getResponseCode()
      Return last HTTP response code.
      Gibt zurück:
      Last HTTP response code
    • getResponseDataAsBytes

      public byte[] getResponseDataAsBytes()
      Return HTTP response data.
      Gibt zurück:
      byte[] HTTP response data
    • getResponseDataAsString

      public String getResponseDataAsString()
      Return HTTP response data.
      Gibt zurück:
      HTTP response data or null
    • getResponseHeaders

      public Properties getResponseHeaders()
      Return last HTTP response headers.
      Gibt zurück:
      HTTP response headers
    • getResponseTimeMs

      public int getResponseTimeMs()
      Get response time of last HTTP request in milliseconds.
      Gibt zurück:
      HTTP response time in milliseconds
    • head

      public boolean head(String argURL, Properties argHeaders)
      Execute HTTP HEAD request.
      Parameter:
      argURL - URL to connect
      argHeaders - Additional HTTP request headers or null
      Gibt zurück:
      True (if HTTP return code 200), else false
    • options

      public boolean options(String argURL, Properties argHeaders)
      Execute HTTP OPTIONS request.
      Parameter:
      argURL - URL to connect
      argHeaders - Additional HTTP request headers or null
      Gibt zurück:
      True (if HTTP return code 200), else false
      Seit:
      2024.05.22
    • patch

      public boolean patch(String argURL, Properties argHeaders, byte[] argPayload)
      Execute HTTP PATCH request.
      Parameter:
      argURL - URL to connect
      argHeaders - Additional HTTP request headers or null
      argPayload - Data to be sent with PATCH request
      Gibt zurück:
      True (if HTTP return code 200), else false
      Seit:
      2024.05.22
    • patch

      public boolean patch(String argURL, Properties argHeaders, String argPayload)
      Execute HTTP PATCH request.
      Parameter:
      argURL - URL to connect
      argHeaders - Additional HTTP request headers or null
      argPayload - Data to be sent with PATCH request
      Gibt zurück:
      True (if HTTP return code 200), else false
      Seit:
      2024.05.22
    • post

      public boolean post(String argURL, Properties argHeaders, byte[] argPayload)
      Execute HTTP POST request.
      Parameter:
      argURL - URL to connect
      argHeaders - Additional HTTP request headers or null
      argPayload - Data to be sent with POST request
      Gibt zurück:
      True (if HTTP return code 200), else false
    • post

      public boolean post(String argURL, Properties argHeaders, String argPayload)
      Execute HTTP POST request.
      Parameter:
      argURL - URL to connect
      argHeaders - Additional HTTP request headers or null
      argPayload - Data to be sent with POST request
      Gibt zurück:
      True (if HTTP return code 200), else false
    • put

      public boolean put(String argURL, Properties argHeaders, byte[] argPayload)
      Execute HTTP PUT request.
      Parameter:
      argURL - URL to connect
      argHeaders - Additional HTTP request headers or null
      argPayload - Data to be sent with PUT request
      Gibt zurück:
      True (if HTTP return code 200), else false
      Seit:
      2024.05.22
    • put

      public boolean put(String argURL, Properties argHeaders, String argPayload)
      Execute HTTP PUT request.
      Parameter:
      argURL - URL to connect
      argHeaders - Additional HTTP request headers or null
      argPayload - Data to be sent with PUT request
      Gibt zurück:
      True (if HTTP return code 200), else false
      Seit:
      2024.05.22
    • toString

      public String toString()
      String representation of object.
      Setzt außer Kraft:
      toString in Klasse Object
      Seit:
      2024.08.23