Class HttpUtils

java.lang.Object
org.eclipse.rdf4j.http.client.spi.HttpUtils

public final class HttpUtils extends Object
Utility methods for working with HttpResponse instances.
  • Method Details

    • toString

      public static String toString(HttpResponse response) throws IOException
      Reads the response body into a String, using the charset declared in the Content-Type header. If no charset parameter is present, ISO-8859-1 is used as the default, consistent with the HTTP/1.1 specification and the behaviour of Apache HttpClient's EntityUtils.toString().

      If the response has no body (e.g. HTTP 204 No Content), an empty string is returned.

      Parameters:
      response - the response whose body is to be read; the caller is responsible for closing the response
      Returns:
      the response body as a string, or an empty string if there is no body
      Throws:
      IOException - if reading the body fails
    • toString

      public static String toString(HttpResponse response, Charset defaultCharset) throws IOException
      Reads the response body into a String, using the charset declared in the Content-Type header. If no charset parameter is present, defaultCharset is used instead.

      If the response has no body (e.g. HTTP 204 No Content), an empty string is returned.

      Parameters:
      response - the response whose body is to be read; the caller is responsible for closing the response
      defaultCharset - the charset to use when none is declared in the Content-Type header
      Returns:
      the response body as a string, or an empty string if there is no body
      Throws:
      IOException - if reading the body fails