类 Request<T>
java.lang.Object
com.android.volley.Request<T>
- 类型参数:
T- The type of parsed response this request expects.
- 所有已实现的接口:
Comparable<Request<T>>
- 直接已知子类:
ClearCacheRequest,GsonRequest,ImageRequest,JsonRequest,StringRequest
Base class for all network requests.
-
嵌套类概要
嵌套类修饰符和类型类说明static interfaceSupported request methods.static enumPriority values. -
构造器概要
构造器构造器说明Request(int method, String url, Response.ErrorListener listener) Creates a new request with the given method (one of the values fromRequest.Method), URL, and error listener.Request(String url, Response.ErrorListener listener) 已过时。 -
方法概要
修饰符和类型方法说明voidAdds an event to this request's event log; for debugging.voidcancel()Mark this request as canceled.intOur comparator sorts from high to low priority, and secondarily by sequence number to provide FIFO ordering.voiddeliverError(VolleyError error) Delivers error message to the ErrorListener that the Request was initialized with.protected abstract voiddeliverResponse(T response) Subclasses must implement this to perform delivery of the parsed response to their listeners.byte[]getBody()Returns the raw POST or PUT body to be sent.Returns the content type of the POST or PUT body.Returns the annotated cache entry, or null if there isn't one.Returns the cache key for this request.Returns a list of extra HTTP headers to go along with this request.intReturn the method for this request.Returns a Map of parameters to be used for a POST or PUT request.protected StringReturns which encoding should be used when converting POST or PUT parameters returned bygetParams()into a raw POST or PUT body.byte[]已过时。UsegetBody()instead.已过时。UsegetBodyContentType()instead.已过时。UsegetParams()instead.protected String已过时。UsegetParamsEncoding()instead.Returns theRequest.Priorityof this request;Request.Priority.NORMALby default.Returns the retry policy that should be used for this request.final intReturns the sequence number of this request.getTag()Returns this request's tag.final intReturns the socket timeout in milliseconds per retry attempt.intgetUrl()Returns the URL of this request.booleanReturns true if this request has had a response delivered for it.booleanReturns true if this request has been canceled.voidMark this request as having a response delivered on it.protected VolleyErrorparseNetworkError(VolleyError volleyError) Subclasses can override this method to parse 'networkError' and return a more specific error.parseNetworkResponse(NetworkResponse response) Subclasses must implement this to parse the raw network response and return an appropriate response type.Request<?>setCacheEntry(Cache.Entry entry) Annotates this request with an entry retrieved for it from cache.Request<?>setRequestQueue(RequestQueue requestQueue) Associates this request with the given queue.Request<?>setRetryPolicy(RetryPolicy retryPolicy) Sets the retry policy for this request.final Request<?>setSequence(int sequence) Sets the sequence number of this request.final Request<?>setShouldCache(boolean shouldCache) Set whether or not responses to this request should be cached.Request<?>Set a tag on this request.final booleanReturns true if responses to this request should be cached.toString()
-
构造器详细资料
-
Request
Creates a new request with the given URL and error listener. Note that the normal response listener is not provided here as delivery of responses is provided by subclasses, who have a better idea of how to deliver an already-parsed response. -
Request
Creates a new request with the given method (one of the values fromRequest.Method), URL, and error listener. Note that the normal response listener is not provided here as delivery of responses is provided by subclasses, who have a better idea of how to deliver an already-parsed response.
-
-
方法详细资料
-
getMethod
public int getMethod()Return the method for this request. Can be one of the values inRequest.Method. -
setTag
Set a tag on this request. Can be used to cancel all requests with this tag byRequestQueue.cancelAll(Object).- 返回:
- This Request object to allow for chaining.
-
getTag
Returns this request's tag.- 另请参阅:
-
getErrorListener
- 返回:
- this request's
Response.ErrorListener.
-
getTrafficStatsTag
public int getTrafficStatsTag()- 返回:
- A tag for use with
TrafficStats.setThreadStatsTag(int)
-
setRetryPolicy
Sets the retry policy for this request.- 返回:
- This Request object to allow for chaining.
-
addMarker
Adds an event to this request's event log; for debugging. -
setRequestQueue
Associates this request with the given queue. The request queue will be notified when this request has finished.- 返回:
- This Request object to allow for chaining.
-
setSequence
Sets the sequence number of this request. Used byRequestQueue.- 返回:
- This Request object to allow for chaining.
-
getSequence
public final int getSequence()Returns the sequence number of this request. -
getUrl
Returns the URL of this request. -
getCacheKey
Returns the cache key for this request. By default, this is the URL. -
setCacheEntry
Annotates this request with an entry retrieved for it from cache. Used for cache coherency support.- 返回:
- This Request object to allow for chaining.
-
getCacheEntry
Returns the annotated cache entry, or null if there isn't one. -
cancel
public void cancel()Mark this request as canceled. No callback will be delivered. -
isCanceled
public boolean isCanceled()Returns true if this request has been canceled. -
getHeaders
Returns a list of extra HTTP headers to go along with this request. Can throwAuthFailureErroras authentication may be required to provide these values.- 抛出:
AuthFailureError- In the event of auth failure
-
getPostParams
已过时。UsegetParams()instead.Returns a Map of POST parameters to be used for this request, or null if a simple GET should be used. Can throwAuthFailureErroras authentication may be required to provide these values.Note that only one of getPostParams() and getPostBody() can return a non-null value.
- 抛出:
AuthFailureError- In the event of auth failure
-
getPostParamsEncoding
已过时。UsegetParamsEncoding()instead.Returns which encoding should be used when converting POST parameters returned bygetPostParams()into a raw POST body.This controls both encodings:
- The string encoding used when converting parameter names and values into bytes prior to URL encoding them.
- The string encoding used when converting the URL encoded parameters into a raw byte array.
-
getPostBodyContentType
已过时。UsegetBodyContentType()instead. -
getPostBody
已过时。UsegetBody()instead.Returns the raw POST body to be sent.- 抛出:
AuthFailureError- In the event of auth failure
-
getParams
Returns a Map of parameters to be used for a POST or PUT request. Can throwAuthFailureErroras authentication may be required to provide these values.Note that you can directly override
getBody()for custom data.- 抛出:
AuthFailureError- in the event of auth failure
-
getParamsEncoding
Returns which encoding should be used when converting POST or PUT parameters returned bygetParams()into a raw POST or PUT body.This controls both encodings:
- The string encoding used when converting parameter names and values into bytes prior to URL encoding them.
- The string encoding used when converting the URL encoded parameters into a raw byte array.
-
getBodyContentType
Returns the content type of the POST or PUT body. -
getBody
Returns the raw POST or PUT body to be sent.By default, the body consists of the request parameters in application/x-www-form-urlencoded format. When overriding this method, consider overriding
getBodyContentType()as well to match the new body format.- 抛出:
AuthFailureError- in the event of auth failure
-
setShouldCache
Set whether or not responses to this request should be cached.- 返回:
- This Request object to allow for chaining.
-
shouldCache
public final boolean shouldCache()Returns true if responses to this request should be cached. -
getPriority
Returns theRequest.Priorityof this request;Request.Priority.NORMALby default. -
getTimeoutMs
public final int getTimeoutMs()Returns the socket timeout in milliseconds per retry attempt. (This value can be changed per retry attempt if a backoff is specified via backoffTimeout()). If there are no retry attempts remaining, this will cause delivery of aTimeoutErrorerror. -
getRetryPolicy
Returns the retry policy that should be used for this request. -
markDelivered
public void markDelivered()Mark this request as having a response delivered on it. This can be used later in the request's lifetime for suppressing identical responses. -
hasHadResponseDelivered
public boolean hasHadResponseDelivered()Returns true if this request has had a response delivered for it. -
parseNetworkResponse
Subclasses must implement this to parse the raw network response and return an appropriate response type. This method will be called from a worker thread. The response will not be delivered if you return null.- 参数:
response- Response from the network- 返回:
- The parsed response, or null in the case of an error
-
parseNetworkError
Subclasses can override this method to parse 'networkError' and return a more specific error.The default implementation just returns the passed 'networkError'.
- 参数:
volleyError- the error retrieved from the network- 返回:
- an NetworkError augmented with additional information
-
deliverResponse
Subclasses must implement this to perform delivery of the parsed response to their listeners. The given response is guaranteed to be non-null; responses that fail to parse are not delivered.- 参数:
response- The parsed response returned byparseNetworkResponse(NetworkResponse)
-
deliverError
Delivers error message to the ErrorListener that the Request was initialized with.- 参数:
error- Error details
-
compareTo
Our comparator sorts from high to low priority, and secondarily by sequence number to provide FIFO ordering.- 指定者:
compareTo在接口中Comparable<T>
-
toString
-
Request(int, String, com.android.volley.Response.ErrorListener).