public class Request
extends BaseRequest
Constructor and Description |
---|
Request(java.lang.String url,
java.lang.String method)
Constructs a new resource request with the specified URL, using the specified HTTP method.
|
Request(java.lang.String url,
java.lang.String method,
int timeout)
Constructs a new resource request with the specified URL, using the specified HTTP method.
|
Request(java.lang.String url,
java.lang.String method,
int timeout,
int autoRetries)
Constructs a new resource request with the specified URL, using the specified HTTP method.
|
Modifier and Type | Method and Description |
---|---|
void |
download(Context context,
byte[] data,
ProgressListener progressListener,
ResponseListener responseListener)
Download this resource asynchronously, with the given byte array as the request body.
|
void |
download(Context context,
JSONObject json,
ProgressListener progressListener,
ResponseListener responseListener)
Download this resource asynchronously, with the given JSON object as the request body.
|
void |
download(Context context,
java.util.Map<java.lang.String,java.lang.String> formParameters,
ProgressListener progressListener,
ResponseListener responseListener)
Download this resource asynchronously, with the given form parameters as the request body.
|
void |
download(Context context,
ProgressListener progressListener,
ResponseListener responseListener)
Download this resource asynchronously, without a request body.
|
void |
download(Context context,
java.lang.String requestBody,
ProgressListener progressListener,
ResponseListener responseListener)
Download this resource asynchronously, with the given string as the request body.
|
java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
getHeaders()
Returns all the headers that were set for this resource request.
|
java.lang.String |
getMethod()
Returns the HTTP method for this resource request.
|
java.util.Map<java.lang.String,java.lang.String> |
getQueryParameters()
Returns the query parameters set for this resource request.
|
int |
getTimeout()
Returns the timeout for this resource request.
|
java.lang.String |
getUrl()
Returns the URL for this resource request.
|
void |
send(Context context,
byte[] data,
ResponseListener listener)
Send this resource request asynchronously, with the given byte array as the request body.
|
void |
send(Context context,
ResponseListener listener)
Send this resource request asynchronously, without a request body.
|
void |
send(Context context,
java.lang.String text,
ResponseListener listener)
Send this resource request asynchronously, with the given string as the request body.
|
void |
setHeaders(java.util.Map<java.lang.String,java.util.List<java.lang.String>> headers)
Sets headers for this resource request.
|
void |
setQueryParameters(java.util.Map<java.lang.String,java.lang.String> parameters)
Sets the query parameters for this resource request.
|
void |
upload(Context context,
byte[] data,
ProgressListener progressListener,
ResponseListener responseListener)
Upload a byte array asynchronously.
|
void |
upload(Context context,
java.io.File file,
ProgressListener progressListener,
ResponseListener responseListener)
Upload a file asynchronously.
|
void |
upload(Context context,
java.lang.String text,
ProgressListener progressListener,
ResponseListener responseListener)
Upload text asynchronously.
|
public Request(java.lang.String url, java.lang.String method)
url
- The resource URL, may be either relative or absolute.method
- The HTTP method to usepublic Request(java.lang.String url, java.lang.String method, int timeout)
url
- The resource URLmethod
- The HTTP method to use.timeout
- The timeout in milliseconds for this request.public Request(java.lang.String url, java.lang.String method, int timeout, int autoRetries)
url
- The resource URLmethod
- The HTTP method to use.timeout
- The timeout in milliseconds for this request.autoRetries
- The number of times to retry each request if it fails due to timeout or loss of network connection.public java.lang.String getUrl()
public java.lang.String getMethod()
public int getTimeout()
public java.util.Map<java.lang.String,java.lang.String> getQueryParameters()
public void setQueryParameters(java.util.Map<java.lang.String,java.lang.String> parameters)
parameters
- A HashMap containing the query parameterspublic java.util.Map<java.lang.String,java.util.List<java.lang.String>> getHeaders()
public void setHeaders(java.util.Map<java.lang.String,java.util.List<java.lang.String>> headers)
headers
- A multimap containing the header names and corresponding valuespublic void send(Context context, ResponseListener listener)
context
- The context that will be passed to authentication listener.listener
- The listener whose onSuccess or onFailure methods will be called when this request finishespublic void send(Context context, java.lang.String text, ResponseListener listener)
context
- The context that will be passed to authentication listener.text
- The text to put in the request bodylistener
- The listener whose onSuccess or onFailure methods will be called when this request finishespublic void send(Context context, byte[] data, ResponseListener listener)
context
- The context that will be passed to authentication listener.data
- The byte array to put in the request bodylistener
- The listener whose onSuccess or onFailure methods will be called when this request finishespublic void download(Context context, ProgressListener progressListener, ResponseListener responseListener)
Download this resource asynchronously, without a request body.
The download progress will be monitored with a ProgressListener
.
Note: This method consumes the InputStream
from the response and closes it,
so the Response.getResponseByteStream()
method will always return null for this request.
context
- The context that will be passed to authentication listener.progressListener
- The listener that monitors the download progressresponseListener
- The listener whose onSuccess or onFailure methods will be called when this request finishespublic void download(Context context, java.lang.String requestBody, ProgressListener progressListener, ResponseListener responseListener)
Download this resource asynchronously, with the given string as the request body.
The download progress will be monitored with a ProgressListener
.
If no Content-Type header was set, this method will set it to "text/plain".
Note: This method consumes the InputStream
from the response and closes it,
so the Response.getResponseByteStream()
method will always return null for this request.
context
- The context that will be passed to authentication listener.requestBody
- The text to put in the request bodyprogressListener
- The listener that monitors the download progressresponseListener
- The listener whose onSuccess or onFailure methods will be called when this request finishespublic void download(Context context, java.util.Map<java.lang.String,java.lang.String> formParameters, ProgressListener progressListener, ResponseListener responseListener)
Download this resource asynchronously, with the given form parameters as the request body.
The download progress will be monitored with a ProgressListener
.
If no Content-Type header was set, this method will set it to "application/x-www-form-urlencoded".
Note: This method consumes the InputStream
from the response and closes it,
so the Response.getResponseByteStream()
method will always return null for this request.
context
- The context that will be passed to authentication listener.formParameters
- The parameters to put in the request bodyprogressListener
- The listener that monitors the download progressresponseListener
- The listener whose onSuccess or onFailure methods will be called when this request finishespublic void download(Context context, JSONObject json, ProgressListener progressListener, ResponseListener responseListener)
Download this resource asynchronously, with the given JSON object as the request body.
The download progress will be monitored with a ProgressListener
.
If no Content-Type header was set, this method will set it to "application/json".
Note: This method consumes the InputStream
from the response and closes it,
so the Response.getResponseByteStream()
method will always return null for this request.
context
- The context that will be passed to authentication listener.json
- The JSON object to put in the request bodyprogressListener
- The listener that monitors the download progressresponseListener
- The listener whose onSuccess or onFailure methods will be called when this request finishespublic void download(Context context, byte[] data, ProgressListener progressListener, ResponseListener responseListener)
Download this resource asynchronously, with the given byte array as the request body.
The download progress will be monitored with a ProgressListener
.
This method does not set any Content-Type header; if such a header is required, it must be set before calling this method.
Note: This method consumes the InputStream
from the response and closes it,
so the Response.getResponseByteStream()
method will always return null for this request.
context
- The context that will be passed to authentication listener.data
- The byte array to put in the request bodyprogressListener
- The listener that monitors the download progressresponseListener
- The listener whose onSuccess or onFailure methods will be called when this request finishespublic void upload(Context context, java.lang.String text, ProgressListener progressListener, ResponseListener responseListener)
context
- The context that will be passed to authentication listener.text
- The text to uploadprogressListener
- The listener that monitors the upload progressresponseListener
- The listener whose onSuccess or onFailure methods will be called when this request finishespublic void upload(Context context, byte[] data, ProgressListener progressListener, ResponseListener responseListener)
context
- The context that will be passed to authentication listener.data
- The byte array to uploadprogressListener
- The listener that monitors the upload progressresponseListener
- The listener whose onSuccess or onFailure methods will be called when this request finishespublic void upload(Context context, java.io.File file, ProgressListener progressListener, ResponseListener responseListener)
context
- The context that will be passed to authentication listener.file
- The file to uploadprogressListener
- The listener that monitors the upload progressresponseListener
- The listener whose onSuccess or onFailure methods will be called when this request finishes