public interface Request
Request
represents a HTTP request, and offers a fluent interface to customize
various attributes such as the path, the headers, the content, etc.
You can create Request
objects via HttpClient.newRequest(String)
and
you can send them using either send()
for a blocking semantic, or
send(Response.Listener)
for an asynchronous semantic.
Response
Modifier and Type | Interface and Description |
---|---|
static interface |
Request.Listener
Listener for request events
|
Modifier and Type | Method and Description |
---|---|
void |
abort()
Attempts to abort the send of this request.
|
boolean |
aborted() |
String |
agent() |
Request |
agent(String agent) |
Request |
attribute(String name,
Object value) |
Map<String,Object> |
attributes() |
ContentProvider |
content() |
Request |
content(ContentProvider content) |
long |
conversation() |
Request |
file(java.nio.file.Path file)
Shortcut method to specify a file as a content for this request, with the default content type of
"application/octect-stream".
|
Request |
file(java.nio.file.Path file,
String contentType)
Shortcut method to specify a file as a content for this request, with the given content type.
|
boolean |
followRedirects() |
Request |
followRedirects(boolean follow) |
Request |
header(String name,
String value) |
HttpFields |
headers() |
String |
host() |
long |
idleTimeout() |
Request |
idleTimeout(long timeout) |
Request.Listener |
listener() |
Request |
listener(Request.Listener listener) |
HttpMethod |
method() |
Request |
method(HttpMethod method) |
Request |
param(String name,
String value) |
Fields |
params() |
String |
path() |
Request |
path(String path) |
int |
port() |
String |
scheme() |
Request |
scheme(String scheme) |
Future<ContentResponse> |
send()
Sends this request and returns a
Future that can be used to wait for the
request and the response to be completed (either with a success or a failure). |
void |
send(Response.Listener listener)
Sends this request and asynchronously notifies the given listener for response events.
|
String |
uri() |
HttpVersion |
version() |
Request |
version(HttpVersion version) |
long conversation()
String scheme()
Request scheme(String scheme)
scheme
- the scheme of this request, such as "http" or "https"String host()
int port()
HttpMethod method()
Request method(HttpMethod method)
method
- the method of this request, such as GET or POSTString path()
Request path(String path)
path
- the path of this request, such as "/"String uri()
HttpVersion version()
Request version(HttpVersion version)
version
- the HTTP version of this request, such as "HTTP/1.1"Fields params()
Request param(String name, String value)
name
- the name of the query parametervalue
- the value of the query parameterHttpFields headers()
Request header(String name, String value)
name
- the name of the headervalue
- the value of the headerRequest attribute(String name, Object value)
name
- the name of the attributevalue
- the value of the attributeContentProvider content()
Request content(ContentProvider content)
content
- the content provider of this requestRequest file(java.nio.file.Path file) throws IOException
file
- the file to uploadIOException
- if the file does not exist or cannot be readRequest file(java.nio.file.Path file, String contentType) throws IOException
file
- the file to uploadcontentType
- the content type of the fileIOException
- if the file does not exist or cannot be readString agent()
Request agent(String agent)
agent
- the user agent for this requestlong idleTimeout()
Request idleTimeout(long timeout)
timeout
- the idle timeout for this requestboolean followRedirects()
Request followRedirects(boolean follow)
follow
- whether this request follows redirectsRequest.Listener listener()
Request listener(Request.Listener listener)
listener
- the listener for request eventsFuture<ContentResponse> send()
Future
that can be used to wait for the
request and the response to be completed (either with a success or a failure).
This method should be used when a simple blocking semantic is needed, and when it is known
that the response content can be buffered without exceeding memory constraints.
For example, this method is not appropriate to download big files from a server; consider using
send(Response.Listener)
instead, passing your own Response.Listener
or a utility
listener such as InputStreamResponseListener
.
The future will return when Response.Listener.onComplete(Result)
is invoked.Future
to wait on for request and response completionResponse.Listener.onComplete(Result)
void send(Response.Listener listener)
listener
- the listener that receives response eventsvoid abort()
aborted()
boolean aborted()
abort()
was calledCopyright © 1995-2012 Mort Bay Consulting. All Rights Reserved.