UrlRequest
  public
  
  
  abstract
  class
  UrlRequest
  
    extends Object
  
  
  
  
  
  
| java.lang.Object | |
| ↳ | android.net.http.UrlRequest | 
Controls an HTTP request (GET, PUT, POST etc).
 Created by UrlRequest.Builder, which can be obtained by calling
 HttpEngine.newUrlRequestBuilder.
 Note: All methods must be called on the Executor passed to
 HttpEngine.newUrlRequestBuilder.
Summary
| Nested classes | |
|---|---|
| 
        
        
        
        
        class | UrlRequest.BuilderBuilder for  | 
| 
        
        
        
        
        interface | UrlRequest.CallbackUsers of the HTTP stack extend this class to receive callbacks indicating the
 progress of a  | 
| 
        
        
        
        
        class | UrlRequest.StatusRequest status values returned by  | 
| 
        
        
        
        
        interface | UrlRequest.StatusListenerListener interface used with  | 
| Constants | |
|---|---|
| int | REQUEST_PRIORITY_HIGHESTHighest request priority. | 
| int | REQUEST_PRIORITY_IDLELowest request priority. | 
| int | REQUEST_PRIORITY_LOWLow request priority. | 
| int | REQUEST_PRIORITY_LOWESTVery low request priority. | 
| int | REQUEST_PRIORITY_MEDIUMMedium request priority. | 
| Public methods | |
|---|---|
| 
        abstract
        
        
        
        
        void | 
      cancel()
      Cancels the request. | 
| 
        abstract
        
        
        
        
        void | 
      followRedirect()
      Follows a pending redirect. | 
| 
        abstract
        
        
        
        
        HeaderBlock | 
      getHeaders()
       | 
| 
        abstract
        
        
        
        
        String | 
      getHttpMethod()
       | 
| 
        abstract
        
        
        
        
        int | 
      getPriority()
       | 
| 
        abstract
        
        
        
        
        void | 
      getStatus(UrlRequest.StatusListener listener)
      Queries the status of the request. | 
| 
        abstract
        
        
        
        
        int | 
      getTrafficStatsTag()
       | 
| 
        abstract
        
        
        
        
        int | 
      getTrafficStatsUid()
       | 
| 
        abstract
        
        
        
        
        boolean | 
      hasTrafficStatsTag()
       | 
| 
        abstract
        
        
        
        
        boolean | 
      hasTrafficStatsUid()
       | 
| 
        abstract
        
        
        
        
        boolean | 
      isCacheDisabled()
       | 
| 
        abstract
        
        
        
        
        boolean | 
      isDirectExecutorAllowed()
       | 
| 
        abstract
        
        
        
        
        boolean | 
      isDone()
      Returns  | 
| 
        abstract
        
        
        
        
        void | 
      read(ByteBuffer buffer)
      Attempts to read part of the response body into the provided buffer. | 
| 
        abstract
        
        
        
        
        void | 
      start()
      Starts the request, all callbacks go to  | 
| Inherited methods | |
|---|---|
Constants
REQUEST_PRIORITY_HIGHEST
public static final int REQUEST_PRIORITY_HIGHEST
Highest request priority. Passed to Builder.setPriority.
Constant Value: 4 (0x00000004)
REQUEST_PRIORITY_IDLE
public static final int REQUEST_PRIORITY_IDLE
Lowest request priority. Passed to Builder.setPriority.
Constant Value: 0 (0x00000000)
REQUEST_PRIORITY_LOW
public static final int REQUEST_PRIORITY_LOW
Low request priority. Passed to Builder.setPriority.
Constant Value: 2 (0x00000002)
REQUEST_PRIORITY_LOWEST
public static final int REQUEST_PRIORITY_LOWEST
Very low request priority. Passed to Builder.setPriority.
Constant Value: 1 (0x00000001)
REQUEST_PRIORITY_MEDIUM
public static final int REQUEST_PRIORITY_MEDIUM
Medium request priority. Passed to Builder.setPriority. This is the
 default priority given to the request.
Constant Value: 3 (0x00000003)
Public methods
cancel
public abstract void cancel ()
Cancels the request. Can be called at any time. onCanceled() will
 be invoked when cancellation is complete and no further callback methods will be invoked. If
 the request has completed or has not started, calling cancel() has no effect and
 onCanceled() will not be invoked. If the Executor passed in during UrlRequest construction runs tasks on a single thread, and cancel() is called on
 that thread, no callback methods (besides onCanceled()) will be invoked after cancel() is called. Otherwise, at most one callback method may be invoked after cancel() has completed.
followRedirect
public abstract void followRedirect ()
Follows a pending redirect. Must only be called at most once for each invocation of onRedirectReceived().
getHeaders
public abstract HeaderBlock getHeaders ()
See UrlRequest.Builder.addHeader(String, String)
| Returns | |
|---|---|
| HeaderBlock | This value cannot be null. | 
getHttpMethod
public abstract String getHttpMethod ()
See UrlRequest.Builder.setHttpMethod(String).
| Returns | |
|---|---|
| String | This value may be null. | 
getPriority
public abstract int getPriority ()
| Returns | |
|---|---|
| int | |
getStatus
public abstract void getStatus (UrlRequest.StatusListener listener)
Queries the status of the request.
This is most useful to query the status of the request before any of the
 UrlRequest.Callback methods are called by Cronet.
 
The listener will be invoked back on the Executor passed in when
 the request was created. While you can assume the callback will be invoked in a timely
 fashion, the API doesn't make any guarantees about the latency, nor does it specify the
 order in which the listener and other callbacks will be invoked.
| Parameters | |
|---|---|
| listener | UrlRequest.StatusListener: aStatusListenerthat will be invoked with
         the request's current status.
 This value cannot benull. | 
getTrafficStatsTag
public abstract int getTrafficStatsTag ()
See Builder.setTrafficStatsTag(int)
| Returns | |
|---|---|
| int | |
getTrafficStatsUid
public abstract int getTrafficStatsUid ()
See Builder.setTrafficStatsUid(int)
| Returns | |
|---|---|
| int | |
hasTrafficStatsTag
public abstract boolean hasTrafficStatsTag ()
See Builder.setTrafficStatsTag(int)
| Returns | |
|---|---|
| boolean | |
hasTrafficStatsUid
public abstract boolean hasTrafficStatsUid ()
See Builder.setTrafficStatsUid(int)
| Returns | |
|---|---|
| boolean | |
isCacheDisabled
public abstract boolean isCacheDisabled ()
See Builder.setCacheDisabled(boolean)
| Returns | |
|---|---|
| boolean | |
isDirectExecutorAllowed
public abstract boolean isDirectExecutorAllowed ()
See UrlRequest.Builder.setDirectExecutorAllowed(boolean)
| Returns | |
|---|---|
| boolean | |
isDone
public abstract boolean isDone ()
Returns true if the request was successfully started and is now finished (completed,
 canceled, or failed).
| Returns | |
|---|---|
| boolean | trueif the request was successfully started and is now finished (completed,
 canceled, or failed). | 
read
public abstract void read (ByteBuffer buffer)
Attempts to read part of the response body into the provided buffer. Must only be called at
 most once in response to each invocation of the onResponseStarted() and onReadCompleted() methods of the
 Callback. Each call will result in an asynchronous call to either the Callback's onReadCompleted() method if data is read, its
 onSucceeded() method if there's no more data to read, or its
 onFailed() method if there's an error.
| Parameters | |
|---|---|
| buffer | ByteBuffer:ByteBufferto write response body to. Must be a direct ByteBuffer. The
 embedder must not read or modify buffer's position, limit, or data between its position and
 limit until the request calls back into theCallback.
 This value cannot benull. | 
start
public abstract void start ()
Starts the request, all callbacks go to Callback. May only be called
 once. May not be called if cancel() has been called.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
