| 构造器和说明 |
|---|
Builder() |
| 限定符和类型 | 方法和说明 |
|---|---|
Request.Builder |
addHeader(String name,
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(String name,
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(String method,
RequestBody body) |
Request.Builder |
patch(RequestBody body) |
Request.Builder |
post(RequestBody body) |
Request.Builder |
put(RequestBody body) |
Request.Builder |
removeHeader(String name)
Removes all headers named
name on this builder. |
<T> Request.Builder |
tag(Class<? super T> type,
T tag)
Attaches
tag to the request using type as a key. |
Request.Builder |
tag(Object tag)
Attaches
tag to the request using Object.class as a key. |
Request.Builder |
url(HttpUrl url) |
Request.Builder |
url(String url)
Sets the URL target of this request.
|
Request.Builder |
url(URL url)
Sets the URL target of this request.
|
public Request.Builder url(HttpUrl url)
public Request.Builder url(String url)
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(URL url)
IllegalArgumentException - if the scheme of url is not http or https.public Request.Builder header(String name, String value)
name to value. If this request already has any headers
with that name, they are all replaced.public Request.Builder addHeader(String name, 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(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(String method, @Nullable RequestBody body)
public Request.Builder tag(@Nullable Object tag)
tag to the request using Object.class as a key.public <T> Request.Builder tag(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()
Copyright © 2025. All rights reserved.