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.CompleteListener) for an asynchronous semantic.
Response| Modifier and Type | Interface and Description |
|---|---|
static interface |
Request.BeginListener
Listener for the request begin event.
|
static interface |
Request.CommitListener
Listener for the request committed event.
|
static interface |
Request.ContentListener
Listener for the request content event.
|
static interface |
Request.FailureListener
Listener for the request failed event.
|
static interface |
Request.HeadersListener
Listener for the request headers event.
|
static interface |
Request.Listener
Listener for all request events.
|
static interface |
Request.QueuedListener
Listener for the request queued event.
|
static interface |
Request.RequestListener
Common, empty, super-interface for request listeners.
|
static interface |
Request.SuccessListener
Listener for the request succeeded event.
|
String getScheme()
Request scheme(String scheme)
scheme - the scheme of this request, such as "http" or "https"String getHost()
int getPort()
String getMethod()
Request method(HttpMethod method)
method - the method of this request, such as GET or POSTRequest method(String method)
method - the method of this request, such as GET or POSTString getPath()
getQuery()Request path(String path)
UTF-8 URL encoded.
For example, if the value for parameter "currency" is the euro symbol € then the
query string for this parameter must be "currency=%E2%82%AC".
For transparent encoding of parameter values, use param(String, String).path - the path of this request, such as "/" or "/path?param=1"String getQuery()
getPath(),
getParams()URI getURI()
HttpVersion getVersion()
Request version(HttpVersion version)
version - the HTTP version of this request, such as "HTTP/1.1"Fields getParams()
Request param(String name, String value)
UTF-8 URL encoded.name - the name of the query parametervalue - the value of the query parameterHttpFields getHeaders()
Request header(String name, String value)
name - the name of the headervalue - the value of the headerheader(HttpHeader, String)Request header(HttpHeader header, String value)
Adds the given value to the specified header.
Multiple calls with the same parameters will add multiple values;
use the value null to remove the header completely.
header - the header namevalue - the value of the headerList<HttpCookie> getCookies()
Request cookie(HttpCookie cookie)
cookie - a cookie for this requestRequest attribute(String name, Object value)
name - the name of the attributevalue - the value of the attributeContentProvider getContent()
Request content(ContentProvider content)
content - the content provider of this requestRequest content(ContentProvider content, String contentType)
content - the content provider of this requestRequest file(Path file) throws IOException
file - the file to uploadIOException - if the file does not exist or cannot be readRequest 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 getAgent()
Request agent(String agent)
agent - the user agent for this request (corresponds to the User-Agent header)Request accept(String... accepts)
accepts - the media types that are acceptable in the response, such as
"text/plain;q=0.5" or "text/html" (corresponds to the Accept header)long getIdleTimeout()
Request idleTimeout(long timeout, TimeUnit unit)
timeout - the idle timeout for this requestunit - the idle timeout unitlong getTimeout()
Request timeout(long timeout, TimeUnit unit)
timeout - the total timeout for the request/response conversationunit - the timeout unitboolean isFollowRedirects()
Request followRedirects(boolean follow)
follow - whether this request follows redirects<T extends Request.RequestListener> List<T> getRequestListeners(Class<T> listenerClass)
listenerClass - the class of the listener, or null for all listeners classesRequest listener(Request.Listener listener)
listener - a listener for request eventsRequest onRequestQueued(Request.QueuedListener listener)
listener - a listener for request queued eventRequest onRequestBegin(Request.BeginListener listener)
listener - a listener for request begin eventRequest onRequestHeaders(Request.HeadersListener listener)
listener - a listener for request headers eventRequest onRequestCommit(Request.CommitListener listener)
listener - a listener for request commit eventRequest onRequestContent(Request.ContentListener listener)
listener - a listener for request content eventsRequest onRequestSuccess(Request.SuccessListener listener)
listener - a listener for request success eventRequest onRequestFailure(Request.FailureListener listener)
listener - a listener for request failure eventRequest onResponseBegin(Response.BeginListener listener)
listener - a listener for response begin eventRequest onResponseHeader(Response.HeaderListener listener)
listener - a listener for response header eventRequest onResponseHeaders(Response.HeadersListener listener)
listener - a listener for response headers eventRequest onResponseContent(Response.ContentListener listener)
listener - a consuming listener for response content eventsRequest onResponseContentAsync(Response.AsyncContentListener listener)
listener - an asynchronous listener for response content eventsRequest onResponseSuccess(Response.SuccessListener listener)
listener - a listener for response success eventRequest onResponseFailure(Response.FailureListener listener)
listener - a listener for response failure eventRequest onComplete(Response.CompleteListener listener)
listener - a listener for complete eventContentResponse send() throws InterruptedException, TimeoutException, ExecutionException
send(Response.CompleteListener) instead, passing your own Response.Listener or a utility
listener such as InputStreamResponseListener.
The method returns when the complete event is fired.ContentResponse for this requestInterruptedExceptionTimeoutExceptionExecutionExceptionResponse.CompleteListener.onComplete(Result)void send(Response.CompleteListener listener)
listener - the listener that receives response eventsboolean abort(Throwable cause)
cause - the abort cause, must not be nullThrowable getAbortCause()
abort(Throwable),
or null if this request has not been abortedCopyright © 1995-2015 Webtide. All Rights Reserved.