Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 7](https://developer.android.com/sdkExtensions) Summary: [Nested Classes](https://developer.android.com/reference/android/net/http/UrlRequest#nestedclasses) \| [Constants](https://developer.android.com/reference/android/net/http/UrlRequest#constants) \| [Methods](https://developer.android.com/reference/android/net/http/UrlRequest#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/net/http/UrlRequest#inhmethods)

# UrlRequest

*** ** * ** ***


`
public


abstract
class
UrlRequest
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.net.http.UrlRequest |

<br />

*** ** * ** ***

Controls an HTTP request (GET, PUT, POST etc).
Created by `https://developer.android.com/reference/android/net/http/UrlRequest.Builder`, which can be obtained by calling
`https://developer.android.com/reference/android/net/http/HttpEngine#newUrlRequestBuilder(java.lang.String,%20java.util.concurrent.Executor,%20android.net.http.UrlRequest.Callback)`.
Note: All methods must be called on the `https://developer.android.com/reference/java/util/concurrent/Executor` passed to
`https://developer.android.com/reference/android/net/http/HttpEngine#newUrlRequestBuilder(java.lang.String,%20java.util.concurrent.Executor,%20android.net.http.UrlRequest.Callback)`.

## Summary

| ### Nested classes ||
|---|---|
| ` class` | `https://developer.android.com/reference/android/net/http/UrlRequest.Builder` Builder for `https://developer.android.com/reference/android/net/http/UrlRequest`s. |
| ` interface` | `https://developer.android.com/reference/android/net/http/UrlRequest.Callback` Users of the HTTP stack extend this class to receive callbacks indicating the progress of a `https://developer.android.com/reference/android/net/http/UrlRequest` being processed. |
| ` class` | `https://developer.android.com/reference/android/net/http/UrlRequest.Status` Request status values returned by `https://developer.android.com/reference/android/net/http/UrlRequest#getStatus(android.net.http.UrlRequest.StatusListener)`. |
| ` interface` | `https://developer.android.com/reference/android/net/http/UrlRequest.StatusListener` Listener interface used with `https://developer.android.com/reference/android/net/http/UrlRequest#getStatus(android.net.http.UrlRequest.StatusListener)` to receive the status of a `https://developer.android.com/reference/android/net/http/UrlRequest`. |

| ### Constants ||
|---|---|
| `int` | `https://developer.android.com/reference/android/net/http/UrlRequest#REQUEST_PRIORITY_HIGHEST` Highest request priority. |
| `int` | `https://developer.android.com/reference/android/net/http/UrlRequest#REQUEST_PRIORITY_IDLE` Lowest request priority. |
| `int` | `https://developer.android.com/reference/android/net/http/UrlRequest#REQUEST_PRIORITY_LOW` Low request priority. |
| `int` | `https://developer.android.com/reference/android/net/http/UrlRequest#REQUEST_PRIORITY_LOWEST` Very low request priority. |
| `int` | `https://developer.android.com/reference/android/net/http/UrlRequest#REQUEST_PRIORITY_MEDIUM` Medium request priority. |

| ### Public methods ||
|---|---|
| ` abstract void` | ` https://developer.android.com/reference/android/net/http/UrlRequest#cancel()() ` Cancels the request. |
| ` abstract void` | ` https://developer.android.com/reference/android/net/http/UrlRequest#followRedirect()() ` Follows a pending redirect. |
| ` https://developer.android.com/reference/android/net/http/FinishedRequestTimings` | ` https://developer.android.com/reference/android/net/http/UrlRequest#getFinishedRequestTimings()() ` Returns the detailed timing metrics for the request. |
| ` abstract https://developer.android.com/reference/android/net/http/HeaderBlock` | ` https://developer.android.com/reference/android/net/http/UrlRequest#getHeaders()() ` See `https://developer.android.com/reference/android/net/http/UrlRequest.Builder#addHeader(java.lang.String,%20java.lang.String)` |
| ` abstract https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/net/http/UrlRequest#getHttpMethod()() ` See `https://developer.android.com/reference/android/net/http/UrlRequest.Builder#setHttpMethod(java.lang.String)`. |
| ` abstract int` | ` https://developer.android.com/reference/android/net/http/UrlRequest#getPriority()() ` See `https://developer.android.com/reference/android/net/http/UrlRequest.Builder#setPriority(int)` |
| ` abstract void` | ` https://developer.android.com/reference/android/net/http/UrlRequest#getStatus(android.net.http.UrlRequest.StatusListener)(https://developer.android.com/reference/android/net/http/UrlRequest.StatusListener listener) ` Queries the status of the request. |
| ` abstract int` | ` https://developer.android.com/reference/android/net/http/UrlRequest#getTrafficStatsTag()() ` See `https://developer.android.com/reference/android/net/http/UrlRequest.Builder#setTrafficStatsTag(int)` |
| ` abstract int` | ` https://developer.android.com/reference/android/net/http/UrlRequest#getTrafficStatsUid()() ` See `https://developer.android.com/reference/android/net/http/UrlRequest.Builder#setTrafficStatsUid(int)` |
| ` abstract boolean` | ` https://developer.android.com/reference/android/net/http/UrlRequest#hasTrafficStatsTag()() ` See `https://developer.android.com/reference/android/net/http/UrlRequest.Builder#setTrafficStatsTag(int)` |
| ` abstract boolean` | ` https://developer.android.com/reference/android/net/http/UrlRequest#hasTrafficStatsUid()() ` See `https://developer.android.com/reference/android/net/http/UrlRequest.Builder#setTrafficStatsUid(int)` |
| ` abstract boolean` | ` https://developer.android.com/reference/android/net/http/UrlRequest#isCacheDisabled()() ` See `https://developer.android.com/reference/android/net/http/UrlRequest.Builder#setCacheDisabled(boolean)` |
| ` abstract boolean` | ` https://developer.android.com/reference/android/net/http/UrlRequest#isDirectExecutorAllowed()() ` See `https://developer.android.com/reference/android/net/http/UrlRequest.Builder#setDirectExecutorAllowed(boolean)` |
| ` abstract boolean` | ` https://developer.android.com/reference/android/net/http/UrlRequest#isDone()() ` Returns `true` if the request was successfully started and is now finished (completed, canceled, or failed). |
| ` abstract void` | ` https://developer.android.com/reference/android/net/http/UrlRequest#read(java.nio.ByteBuffer)(https://developer.android.com/reference/java/nio/ByteBuffer buffer) ` Attempts to read part of the response body into the provided buffer. |
| ` abstract void` | ` https://developer.android.com/reference/android/net/http/UrlRequest#start()() ` Starts the request, all callbacks go to `https://developer.android.com/reference/android/net/http/UrlRequest.Callback`. |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` https://developer.android.com/reference/java/lang/Object#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait()() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||

## Constants

### REQUEST_PRIORITY_HIGHEST

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 7](https://developer.android.com/sdkExtensions)

```
public static final int REQUEST_PRIORITY_HIGHEST
```

Highest request priority. Passed to `https://developer.android.com/reference/android/net/http/UrlRequest.Builder#setPriority(int)`.

<br />

Constant Value:

4
(0x00000004)


### REQUEST_PRIORITY_IDLE

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 7](https://developer.android.com/sdkExtensions)

```
public static final int REQUEST_PRIORITY_IDLE
```

Lowest request priority. Passed to `https://developer.android.com/reference/android/net/http/UrlRequest.Builder#setPriority(int)`.

<br />

Constant Value:

0
(0x00000000)


### REQUEST_PRIORITY_LOW

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 7](https://developer.android.com/sdkExtensions)

```
public static final int REQUEST_PRIORITY_LOW
```

Low request priority. Passed to `https://developer.android.com/reference/android/net/http/UrlRequest.Builder#setPriority(int)`.

<br />

Constant Value:

2
(0x00000002)


### REQUEST_PRIORITY_LOWEST

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 7](https://developer.android.com/sdkExtensions)

```
public static final int REQUEST_PRIORITY_LOWEST
```

Very low request priority. Passed to `https://developer.android.com/reference/android/net/http/UrlRequest.Builder#setPriority(int)`.

<br />

Constant Value:

1
(0x00000001)


### REQUEST_PRIORITY_MEDIUM

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 7](https://developer.android.com/sdkExtensions)

```
public static final int REQUEST_PRIORITY_MEDIUM
```

Medium request priority. Passed to `https://developer.android.com/reference/android/net/http/UrlRequest.Builder#setPriority(int)`. This is the
default priority given to the request.

<br />

Constant Value:

3
(0x00000003)


## Public methods

### cancel

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 7](https://developer.android.com/sdkExtensions)

```
public abstract void cancel ()
```

Cancels the request. Can be called at any time. `https://developer.android.com/reference/android/net/http/UrlRequest.Callback#onCanceled(android.net.http.UrlRequest,%20android.net.http.UrlResponseInfo)` 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 `https://developer.android.com/reference/java/util/concurrent/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.

<br />

### followRedirect

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 7](https://developer.android.com/sdkExtensions)

```
public abstract void followRedirect ()
```

Follows a pending redirect. Must only be called at most once for each invocation of `https://developer.android.com/reference/android/net/http/UrlRequest.Callback#onRedirectReceived(android.net.http.UrlRequest,%20android.net.http.UrlResponseInfo,%20java.lang.String)`.

<br />

### getFinishedRequestTimings

Added in [version 37.1](https://developer.android.com/topic/libraries/support-library/revisions)  
Also in [S Extensions 23](https://developer.android.com/sdkExtensions)

```
public FinishedRequestTimings getFinishedRequestTimings ()
```

Returns the detailed timing metrics for the request.

This method can be only called when the request has reached a terminal callback. This is
defined by the execution of one of the following callbacks: `https://developer.android.com/reference/android/net/http/UrlRequest.Callback#onSucceeded(android.net.http.UrlRequest,%20android.net.http.UrlResponseInfo)`, `https://developer.android.com/reference/android/net/http/UrlRequest.Callback#onFailed(android.net.http.UrlRequest,%20android.net.http.UrlResponseInfo,%20android.net.http.HttpException)` or `https://developer.android.com/reference/android/net/http/UrlRequest.Callback#onCanceled(android.net.http.UrlRequest,%20android.net.http.UrlResponseInfo)`. It's also allowed to call this method in the terminal
callback itself.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/net/http/FinishedRequestTimings` | This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException` | If called before the terminal callback is called. |

### getHeaders

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 7](https://developer.android.com/sdkExtensions)

```
public abstract HeaderBlock getHeaders ()
```

See `https://developer.android.com/reference/android/net/http/UrlRequest.Builder#addHeader(java.lang.String,%20java.lang.String)`

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/net/http/HeaderBlock` | This value cannot be `null`. <br /> |

### getHttpMethod

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 7](https://developer.android.com/sdkExtensions)

```
public abstract String getHttpMethod ()
```

See `https://developer.android.com/reference/android/net/http/UrlRequest.Builder#setHttpMethod(java.lang.String)`.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | This value may be `null`. <br /> |

### getPriority

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 7](https://developer.android.com/sdkExtensions)

```
public abstract int getPriority ()
```

See `https://developer.android.com/reference/android/net/http/UrlRequest.Builder#setPriority(int)`

<br />

| Returns ||
|---|---|
| `int` | <br /> |

### getStatus

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 7](https://developer.android.com/sdkExtensions)

```
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
`https://developer.android.com/reference/android/net/http/UrlRequest.Callback` methods are called by Cronet.

The `listener` will be invoked back on the `https://developer.android.com/reference/java/util/concurrent/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.

<br />

| Parameters ||
|---|---|
| `listener` | `UrlRequest.StatusListener`: a `https://developer.android.com/reference/android/net/http/UrlRequest.StatusListener` that will be invoked with the request's current status. This value cannot be `null`. <br /> |

### getTrafficStatsTag

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 7](https://developer.android.com/sdkExtensions)

```
public abstract int getTrafficStatsTag ()
```

See `https://developer.android.com/reference/android/net/http/UrlRequest.Builder#setTrafficStatsTag(int)`

<br />

| Returns ||
|---|---|
| `int` | <br /> |

### getTrafficStatsUid

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 7](https://developer.android.com/sdkExtensions)

```
public abstract int getTrafficStatsUid ()
```

See `https://developer.android.com/reference/android/net/http/UrlRequest.Builder#setTrafficStatsUid(int)`

<br />

| Returns ||
|---|---|
| `int` | <br /> |

### hasTrafficStatsTag

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 7](https://developer.android.com/sdkExtensions)

```
public abstract boolean hasTrafficStatsTag ()
```

See `https://developer.android.com/reference/android/net/http/UrlRequest.Builder#setTrafficStatsTag(int)`

<br />

| Returns ||
|---|---|
| `boolean` | <br /> |

### hasTrafficStatsUid

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 7](https://developer.android.com/sdkExtensions)

```
public abstract boolean hasTrafficStatsUid ()
```

See `https://developer.android.com/reference/android/net/http/UrlRequest.Builder#setTrafficStatsUid(int)`

<br />

| Returns ||
|---|---|
| `boolean` | <br /> |

### isCacheDisabled

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 7](https://developer.android.com/sdkExtensions)

```
public abstract boolean isCacheDisabled ()
```

See `https://developer.android.com/reference/android/net/http/UrlRequest.Builder#setCacheDisabled(boolean)`

<br />

| Returns ||
|---|---|
| `boolean` | <br /> |

### isDirectExecutorAllowed

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 7](https://developer.android.com/sdkExtensions)

```
public abstract boolean isDirectExecutorAllowed ()
```

See `https://developer.android.com/reference/android/net/http/UrlRequest.Builder#setDirectExecutorAllowed(boolean)`

<br />

| Returns ||
|---|---|
| `boolean` | <br /> |

### isDone

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 7](https://developer.android.com/sdkExtensions)

```
public abstract boolean isDone ()
```

Returns `true` if the request was successfully started and is now finished (completed,
canceled, or failed).

<br />

| Returns ||
|---|---|
| `boolean` | `true` if the request was successfully started and is now finished (completed, canceled, or failed). <br /> |

### read

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 7](https://developer.android.com/sdkExtensions)

```
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 `https://developer.android.com/reference/android/net/http/UrlRequest.Callback#onResponseStarted(android.net.http.UrlRequest,%20android.net.http.UrlResponseInfo)` and `https://developer.android.com/reference/android/net/http/UrlRequest.Callback#onReadCompleted(android.net.http.UrlRequest,%20android.net.http.UrlResponseInfo,%20java.nio.ByteBuffer)` methods of the
`https://developer.android.com/reference/android/net/http/UrlRequest.Callback`. Each call will result in an asynchronous call to either the `https://developer.android.com/reference/android/net/http/UrlRequest.Callback` `https://developer.android.com/reference/android/net/http/UrlRequest.Callback#onReadCompleted(android.net.http.UrlRequest,%20android.net.http.UrlResponseInfo,%20java.nio.ByteBuffer)` method if data is read, its
`https://developer.android.com/reference/android/net/http/UrlRequest.Callback#onSucceeded(android.net.http.UrlRequest,%20android.net.http.UrlResponseInfo)` method if there's no more data to read, or its
`https://developer.android.com/reference/android/net/http/UrlRequest.Callback#onFailed(android.net.http.UrlRequest,%20android.net.http.UrlResponseInfo,%20android.net.http.HttpException)` method if there's an error.

<br />

| Parameters ||
|---|---|
| `buffer` | `ByteBuffer`: `https://developer.android.com/reference/java/nio/ByteBuffer` to 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 the `https://developer.android.com/reference/android/net/http/UrlRequest.Callback`. This value cannot be `null`. <br /> |

### start

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 7](https://developer.android.com/sdkExtensions)

```
public abstract void start ()
```

Starts the request, all callbacks go to `https://developer.android.com/reference/android/net/http/UrlRequest.Callback`. May only be called
once. May not be called if `https://developer.android.com/reference/android/net/http/UrlRequest#cancel()` has been called.

<br />