public static class Request.Builder
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
(package private) RequestBody |
body |
(package private) Headers.Builder |
headers |
(package private) java.lang.String |
method |
(package private) java.util.Map<java.lang.Class<?>,java.lang.Object> |
tags
A mutable map of tags, or an immutable empty map if we don't have any.
|
(package private) HttpUrl |
url |
Modifier and Type | Method and Description |
---|---|
Request.Builder |
addHeader(java.lang.String name,
java.lang.String value)
Adds a header with
name and value . |
Request |
build() |
Request.Builder |
cacheControl(CacheControl cacheControl)
Sets this request's
Cache-Control header, replacing any cache control headers already
present. |
Request.Builder |
delete() |
Request.Builder |
delete(RequestBody body) |
Request.Builder |
get() |
Request.Builder |
head() |
Request.Builder |
header(java.lang.String name,
java.lang.String value)
Sets the header named
name to value . |
Request.Builder |
headers(Headers headers)
Removes all headers on this builder and adds
headers . |
Request.Builder |
method(java.lang.String method,
RequestBody body) |
Request.Builder |
patch(RequestBody body) |
Request.Builder |
post(RequestBody body) |
Request.Builder |
put(RequestBody body) |
Request.Builder |
removeHeader(java.lang.String name)
Removes all headers named
name on this builder. |
<T> Request.Builder |
tag(java.lang.Class<? super T> type,
T tag)
Attaches
tag to the request using type as a key. |
Request.Builder |
tag(java.lang.Object tag)
Attaches
tag to the request using Object.class as a key. |
Request.Builder |
url(HttpUrl url) |
Request.Builder |
url(java.lang.String url)
Sets the URL target of this request.
|
Request.Builder |
url(java.net.URL url)
Sets the URL target of this request.
|
@Nullable HttpUrl url
java.lang.String method
Headers.Builder headers
@Nullable RequestBody body
java.util.Map<java.lang.Class<?>,java.lang.Object> tags
public Builder()
Builder(Request request)
public Request.Builder url(HttpUrl url)
public Request.Builder url(java.lang.String url)
java.lang.IllegalArgumentException
- if url
is not a valid HTTP or HTTPS URL. Avoid this
exception by calling HttpUrl.parse(java.lang.String)
; it returns null for invalid URLs.public Request.Builder url(java.net.URL url)
java.lang.IllegalArgumentException
- if the scheme of url
is not http
or https
.public Request.Builder header(java.lang.String name, java.lang.String value)
name
to value
. If this request already has any headers
with that name, they are all replaced.public Request.Builder addHeader(java.lang.String name, java.lang.String value)
name
and value
. Prefer this method for multiply-valued
headers like "Cookie".
Note that for some headers including Content-Length
and Content-Encoding
,
OkHttp may replace value
with a header derived from the request body.
public Request.Builder removeHeader(java.lang.String name)
name
on this builder.public Request.Builder headers(Headers headers)
headers
.public Request.Builder cacheControl(CacheControl cacheControl)
Cache-Control
header, replacing any cache control headers already
present. If cacheControl
doesn't define any directives, this clears this request's
cache-control headers.public Request.Builder get()
public Request.Builder head()
public Request.Builder post(RequestBody body)
public Request.Builder delete(@Nullable RequestBody body)
public Request.Builder delete()
public Request.Builder put(RequestBody body)
public Request.Builder patch(RequestBody body)
public Request.Builder method(java.lang.String method, @Nullable RequestBody body)
public Request.Builder tag(@Nullable java.lang.Object tag)
tag
to the request using Object.class
as a key.public <T> Request.Builder tag(java.lang.Class<? super T> type, @Nullable T tag)
tag
to the request using type
as a key. Tags can be read from a
request using Request.tag()
. Use null to remove any existing tag assigned for type
.
Use this API to attach timing, debugging, or other application data to a request so that you may read it in interceptors, event listeners, or callbacks.
public Request build()