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: [Methods](https://developer.android.com/reference/android/net/http/UrlRequest.Builder#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/net/http/UrlRequest.Builder#inhmethods)

# UrlRequest.Builder

*** ** * ** ***

` public static abstract class UrlRequest.Builder `   
` extends https://developer.android.com/reference/java/lang/Object ` ` `

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

<br />

*** ** * ** ***

Builder for `https://developer.android.com/reference/android/net/http/UrlRequest`s. Allows configuring requests before constructing them with `https://developer.android.com/reference/android/net/http/UrlRequest.Builder#build()`. The builder can be created by calling `https://developer.android.com/reference/android/net/http/HttpEngine#newUrlRequestBuilder(java.lang.String,%20java.util.concurrent.Executor,%20android.net.http.UrlRequest.Callback)`.

## Summary

| ### Public methods ||
|---|---|
| ` abstract https://developer.android.com/reference/android/net/http/UrlRequest.Builder` | ` https://developer.android.com/reference/android/net/http/UrlRequest.Builder#addHeader(java.lang.String,%20java.lang.String)(https://developer.android.com/reference/java/lang/String header, https://developer.android.com/reference/java/lang/String value) ` Adds a request header. |
| ` abstract https://developer.android.com/reference/android/net/http/UrlRequest.Builder` | ` https://developer.android.com/reference/android/net/http/UrlRequest.Builder#bindToNetwork(android.net.Network)(https://developer.android.com/reference/android/net/Network network) ` Binds the request to the specified network. |
| ` abstract https://developer.android.com/reference/android/net/http/UrlRequest` | ` https://developer.android.com/reference/android/net/http/UrlRequest.Builder#build()() ` Creates a `https://developer.android.com/reference/android/net/http/UrlRequest` using configuration within this `https://developer.android.com/reference/android/net/http/UrlRequest.Builder`. |
| ` abstract https://developer.android.com/reference/android/net/http/UrlRequest.Builder` | ` https://developer.android.com/reference/android/net/http/UrlRequest.Builder#setCacheDisabled(boolean)(boolean disableCache) ` WARNING: This method should not be called with \`setCacheDisabled(false)\` as this may lead to incorrect behaviour on older versions of HttpEngine. |
| ` abstract https://developer.android.com/reference/android/net/http/UrlRequest.Builder` | ` https://developer.android.com/reference/android/net/http/UrlRequest.Builder#setDirectExecutorAllowed(boolean)(boolean allowDirectExecutor) ` WARNING: This method should not be called with \`setDirectExecutorAllowed(false)\` as this may lead to incorrect behaviour on older versions of HttpEngine. |
| ` abstract https://developer.android.com/reference/android/net/http/UrlRequest.Builder` | ` https://developer.android.com/reference/android/net/http/UrlRequest.Builder#setHttpMethod(java.lang.String)(https://developer.android.com/reference/java/lang/String method) ` Sets the HTTP method verb to use for this request. |
| ` abstract https://developer.android.com/reference/android/net/http/UrlRequest.Builder` | ` https://developer.android.com/reference/android/net/http/UrlRequest.Builder#setPriority(int)(int priority) ` Sets priority of the request which should be one of the `https://developer.android.com/reference/android/net/http/UrlRequest#REQUEST_PRIORITY_IDLE` values. |
| ` abstract https://developer.android.com/reference/android/net/http/UrlRequest.Builder` | ` https://developer.android.com/reference/android/net/http/UrlRequest.Builder#setTrafficStatsTag(int)(int tag) ` Sets `https://developer.android.com/reference/android/net/TrafficStats` tag to use when accounting socket traffic caused by this request. |
| ` abstract https://developer.android.com/reference/android/net/http/UrlRequest.Builder` | ` https://developer.android.com/reference/android/net/http/UrlRequest.Builder#setTrafficStatsUid(int)(int uid) ` Sets specific UID to use when accounting socket traffic caused by this request. |
| ` abstract https://developer.android.com/reference/android/net/http/UrlRequest.Builder` | ` https://developer.android.com/reference/android/net/http/UrlRequest.Builder#setUploadDataProvider(android.net.http.UploadDataProvider,%20java.util.concurrent.Executor)(https://developer.android.com/reference/android/net/http/UploadDataProvider uploadDataProvider, https://developer.android.com/reference/java/util/concurrent/Executor executor) ` Sets upload data provider. |

### 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*.

## Public methods

### addHeader

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 UrlRequest.Builder addHeader (String header, 
                String value)
```

Adds a request header.

<br />

| Parameters ||
|---|---|
| `header` | `String`: header name. This value cannot be `null`. <br /> |
| `value` | `String`: header value. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/net/http/UrlRequest.Builder` | the builder to facilitate chaining. This value cannot be `null`. <br /> |

### bindToNetwork

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 UrlRequest.Builder bindToNetwork (Network network)
```

Binds the request to the specified network. The HTTP stack will send this request only using the network associated to this handle. If this network disconnects the request will fail, the exact error will depend on the stage of request processing when the network disconnects.

<br />

| Parameters ||
|---|---|
| `network` | `Network`: the network to bind the request to. Specify `null` to unbind. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/net/http/UrlRequest.Builder` | the builder to facilitate chaining. This value cannot be `null`. <br /> |

### build

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 UrlRequest build ()
```

Creates a `https://developer.android.com/reference/android/net/http/UrlRequest` using configuration within this `https://developer.android.com/reference/android/net/http/UrlRequest.Builder`. The returned `UrlRequest` can then be started by calling `https://developer.android.com/reference/android/net/http/UrlRequest#start()`.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/net/http/UrlRequest` | constructed `https://developer.android.com/reference/android/net/http/UrlRequest` using configuration within this `https://developer.android.com/reference/android/net/http/UrlRequest.Builder`. This value cannot be `null`. <br /> |

### setCacheDisabled

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 UrlRequest.Builder setCacheDisabled (boolean disableCache)
```

WARNING: This method should not be called with \`setCacheDisabled(false)\` as this may lead to incorrect behaviour on older versions of HttpEngine. Whether to disable cache for the request. If the engine is not set up to use cache, this call has no effect.

<br />

| Parameters ||
|---|---|
| `disableCache` | `boolean`: `true` to disable cache, `false` otherwise. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/net/http/UrlRequest.Builder` | the builder to facilitate chaining. This value cannot be `null`. <br /> |

### setDirectExecutorAllowed

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 UrlRequest.Builder setDirectExecutorAllowed (boolean allowDirectExecutor)
```

WARNING: This method should not be called with \`setDirectExecutorAllowed(false)\` as this may lead to incorrect behaviour on older versions of HttpEngine. Marks whether the executors this request will use to notify callbacks (for `UploadDataProvider`s and `UrlRequest.Callback`s) is intentionally performing inline execution, like Guava's directExecutor or `https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor.CallerRunsPolicy`.

**Warning:** If set to true: This option makes it easy to accidentally block the network thread. This should not be done if your callbacks perform disk I/O, acquire locks, or call into other code you don't carefully control and audit.

<br />

| Parameters ||
|---|---|
| `allowDirectExecutor` | `boolean`: `true` to allow executors performing inline execution, `false` otherwise. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/net/http/UrlRequest.Builder` | the builder to facilitate chaining. This value cannot be `null`. <br /> |

### setHttpMethod

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 UrlRequest.Builder setHttpMethod (String method)
```

Sets the HTTP method verb to use for this request.

The default when this method is not called is "GET" if the request has no body or "POST" if it does.

<br />

| Parameters ||
|---|---|
| `method` | `String`: "GET", "HEAD", "DELETE", "POST" or "PUT". This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/net/http/UrlRequest.Builder` | the builder to facilitate chaining. This value cannot be `null`. <br /> |

### setPriority

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 UrlRequest.Builder setPriority (int priority)
```

Sets priority of the request which should be one of the `https://developer.android.com/reference/android/net/http/UrlRequest#REQUEST_PRIORITY_IDLE` values. The request is given `https://developer.android.com/reference/android/net/http/UrlRequest#REQUEST_PRIORITY_MEDIUM` priority if this method is not called.

<br />

| Parameters ||
|---|---|
| `priority` | `int`: priority of the request which should be one of the `https://developer.android.com/reference/android/net/http/UrlRequest#REQUEST_PRIORITY_IDLE` values. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/net/http/UrlRequest.Builder` | the builder to facilitate chaining. This value cannot be `null`. <br /> |

### setTrafficStatsTag

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 UrlRequest.Builder setTrafficStatsTag (int tag)
```

Sets `https://developer.android.com/reference/android/net/TrafficStats` tag to use when accounting socket traffic caused by this request. See `https://developer.android.com/reference/android/net/TrafficStats` for more information. If no tag is set (e.g. this method isn't called), then Android accounts for the socket traffic caused by this request as if the tag value were set to 0.

**NOTE:**Setting a tag disallows sharing of sockets with requests with other tags, which may adversely effect performance by prohibiting connection sharing. In other words use of multiplexed sockets (e.g. HTTP/2 and QUIC) will only be allowed if all requests have the same socket tag.

<br />

| Parameters ||
|---|---|
| `tag` | `int`: the tag value used to when accounting for socket traffic caused by this request. Tags between 0xFFFFFF00 and 0xFFFFFFFF are reserved and used internally by system services like `https://developer.android.com/reference/android/app/DownloadManager` when performing traffic on behalf of an application. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/net/http/UrlRequest.Builder` | the builder to facilitate chaining. This value cannot be `null`. <br /> |

### setTrafficStatsUid

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 UrlRequest.Builder setTrafficStatsUid (int uid)
```

Sets specific UID to use when accounting socket traffic caused by this request. See `https://developer.android.com/reference/android/net/TrafficStats` for more information. Designed for use when performing an operation on behalf of another application. Caller must hold `android.Manifest.permission#MODIFY_NETWORK_ACCOUNTING` permission. By default traffic is attributed to UID of caller.

**NOTE:**Setting a UID disallows sharing of sockets with requests with other UIDs, which may adversely effect performance by prohibiting connection sharing. In other words use of multiplexed sockets (e.g. HTTP/2 and QUIC) will only be allowed if all requests have the same UID set.

<br />

| Parameters ||
|---|---|
| `uid` | `int`: the UID to attribute socket traffic caused by this request. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/net/http/UrlRequest.Builder` | the builder to facilitate chaining. This value cannot be `null`. <br /> |

### setUploadDataProvider

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 UrlRequest.Builder setUploadDataProvider (UploadDataProvider uploadDataProvider, 
                Executor executor)
```

Sets upload data provider. Switches method to "POST" if not explicitly set. Starting the request will throw an exception if a Content-Type header is not set.

<br />

| Parameters ||
|---|---|
| `uploadDataProvider` | `UploadDataProvider`: responsible for providing the upload data. This value cannot be `null`. <br /> |
| `executor` | `Executor`: All `uploadDataProvider` methods will be invoked using this `Executor`. May optionally be the same `Executor` the request itself is using. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/net/http/UrlRequest.Builder` | the builder to facilitate chaining. This value cannot be `null`. <br /> |