Interface HttpRequest
public interface HttpRequest
Represents one HTTP request which can be sent to a server.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceA request processor which obtains the request body from some source.static interfaceBuilder of HTTP requests. -
Method Summary
Modifier and TypeMethodDescriptionstatic HttpRequest.BodyProcessorcreateFormUrlEncodedBodyProcessor(Map<String, ?> parameters) Create aHttpRequest.BodyProcessorthat form URL-encodes the given map of parametersbooleanstatic HttpRequest.BodyProcessorfromByteArray(byte[] buf) static HttpRequest.BodyProcessorfromByteArray(byte[] buf, int offset, int length) static HttpRequest.BodyProcessorCreate aHttpRequest.BodyProcessorfrom the provided object, which is serialized into the JSON format.static HttpRequest.BodyProcessorfromString(String body) Deprecated.static HttpRequest.BodyProcessorfromString(String body, Charset charset) Create aHttpRequest.BodyProcessorfrom the provided String, using the provided encoding.headers()The (user-accessible) request headers that this request was (or will be) sent with.method()static HttpRequest.BodyProcessornoBody()response()Returns the response to this request, by sending it and blocking if necessary to get the response.uri()version()
-
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 callingresponse(), may modify the headers; e.g. Content-Length can be determined from the appliedHttpRequest.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
HttpClient.Version version()- Returns:
- HTTP protocol version
-
noBody
- Returns:
- a request processor which sends no request body
-
fromByteArray
- Parameters:
buf- the byte array containing the body- Returns:
- a request processor whose body is the given byte array
-
fromByteArray
- Parameters:
buf- the byte array containing the bodyoffset- the offset of the first bytelength- the numbers of bytes to use- Returns:
- a request processor whose body is the given byte array
-
fromString
Deprecated.UsefromString(String, Charset)insteadCreate aHttpRequest.BodyProcessorfrom 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
Create aHttpRequest.BodyProcessorfrom the provided object, which is serialized into the JSON format.- Parameters:
body- the object to be serialized as JSONjsonService- to use for JSON serialization- Returns:
- a request processor whose body is the given String.
- Since:
- 4.0.0
-
fromString
Create aHttpRequest.BodyProcessorfrom the provided String, using the provided encoding.- Parameters:
body- the String containing the bodycharset- the charset of the body- Returns:
- a request processor whose body is the given String.
-
createFormUrlEncodedBodyProcessor
Create aHttpRequest.BodyProcessorthat 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
-
fromString(String, Charset)instead