Interface HttpRequest


public interface HttpRequest
Represents one HTTP request which can be sent to a server.
  • Method Details

    • expectContinue

      boolean expectContinue()
      Returns:
      this request's expect continue setting
    • followRedirects

      HttpClient.Redirect followRedirects()
      Returns:
      the follow-redirects setting for this request
    • headers

      HttpHeaders headers()
      The (user-accessible) request headers that this request was (or will be) sent with. Submitting the request, by calling response(), may modify the headers; e.g. Content-Length can be determined from the applied HttpRequest.BodyProcessor.
      Returns:
      this request's HttpHeaders
    • method

      String method()
      Returns:
      this request's method
    • response

      HttpResponse response()
      Returns the response to this request, by sending it and blocking if necessary to get the response.
      Returns:
      a HttpResponse for this request
      Throws:
      HttpClient.HttpClientException - if the request failed
    • uri

      URI uri()
      Returns:
      this request's URI
    • version

      Returns:
      HTTP protocol version
    • noBody

      static HttpRequest.BodyProcessor noBody()
      Returns:
      a request processor which sends no request body
    • fromByteArray

      static HttpRequest.BodyProcessor fromByteArray(byte[] buf)
      Parameters:
      buf - the byte array containing the body
      Returns:
      a request processor whose body is the given byte array
    • fromByteArray

      static HttpRequest.BodyProcessor fromByteArray(byte[] buf, int offset, int length)
      Parameters:
      buf - the byte array containing the body
      offset - the offset of the first byte
      length - the numbers of bytes to use
      Returns:
      a request processor whose body is the given byte array
    • fromString

      @Deprecated static HttpRequest.BodyProcessor fromString(String body)
      Deprecated.
      Create a HttpRequest.BodyProcessor from the provided String, using UTF-8 encoding.
      Parameters:
      body - the String containing the body
      Returns:
      a request processor whose body is the given String.
    • fromJson

      static HttpRequest.BodyProcessor fromJson(Object body, Json jsonService)
      Create a HttpRequest.BodyProcessor from the provided object, which is serialized into the JSON format.
      Parameters:
      body - the object to be serialized as JSON
      jsonService - to use for JSON serialization
      Returns:
      a request processor whose body is the given String.
      Since:
      4.0.0
    • fromString

      static HttpRequest.BodyProcessor fromString(String body, Charset charset)
      Create a HttpRequest.BodyProcessor from the provided String, using the provided encoding.
      Parameters:
      body - the String containing the body
      charset - the charset of the body
      Returns:
      a request processor whose body is the given String.
    • createFormUrlEncodedBodyProcessor

      static HttpRequest.BodyProcessor createFormUrlEncodedBodyProcessor(Map<String,?> parameters)
      Create a HttpRequest.BodyProcessor that form URL-encodes the given map of parameters
      Parameters:
      parameters - the key/value pairs that should be encoded and included in the body. Object.toString() will be called on each value before encoding.
      Returns:
      a BodyProcessor that handles the encoded parameters
      Since:
      2.4.0