Class OkHttpRequest

java.lang.Object
com.landawn.abacus.http.OkHttpRequest

public final class OkHttpRequest extends Object
Note: This class contains the codes and docs copied from OkHttp: https://square.github.io/okhttp/ under Apache License v2.
Since:
1.3
  • Method Details

    • create

      public static OkHttpRequest create(String url, okhttp3.OkHttpClient httpClient)
    • create

      public static OkHttpRequest create(URL url, okhttp3.OkHttpClient httpClient)
    • create

      public static OkHttpRequest create(okhttp3.HttpUrl url, okhttp3.OkHttpClient httpClient)
    • url

      public static OkHttpRequest url(String url)
      Sets the URL target of this request.
      Throws:
      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.
    • url

      public static OkHttpRequest url(URL url)
      Sets the URL target of this request.
      Throws:
      IllegalArgumentException - if the scheme of url is not http or https.
    • url

      public static OkHttpRequest url(okhttp3.HttpUrl url)
    • url

      public static OkHttpRequest url(String url, long connectionTimeoutInMillis, long readTimeoutInMillis)
    • url

      public static OkHttpRequest url(URL url, long connectionTimeoutInMillis, long readTimeoutInMillis)
    • url

      public static OkHttpRequest url(okhttp3.HttpUrl url, long connectionTimeoutInMillis, long readTimeoutInMillis)
    • cacheControl

      public OkHttpRequest cacheControl(okhttp3.CacheControl cacheControl)
      Sets this request's 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.
    • tag

      public OkHttpRequest tag(@Nullable Object tag)
      Attaches tag to the request. It can be used later to cancel the request. If the tag is unspecified or null, the request is canceled by using the request itself as the tag.
    • tag

      public <T> OkHttpRequest tag(Class<? super T> type, @Nullable T tag)
      Attaches 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.

    • basicAuth

      public OkHttpRequest basicAuth(String user, Object password)
      Parameters:
      user -
      password -
      Returns:
    • header

      public OkHttpRequest header(String name, String value)
      Sets the header named name to value. If this request already has any headers with that name, they are all replaced.
      Parameters:
      name -
      value -
      Returns:
      See Also:
      • Request.Builder.header(String, String)
    • headers

      public OkHttpRequest headers(String name1, String value1, String name2, String value2)
      Set http headers specified by name1/value1, name2/value2. If this request already has any headers with that name, they are all replaced.
      Parameters:
      name1 -
      value1 -
      name2 -
      value2 -
      Returns:
      See Also:
      • Request.Builder.header(String, String)
    • headers

      public OkHttpRequest headers(String name1, String value1, String name2, String value2, String name3, String value3)
      Set http headers specified by name1/value1, name2/value2, name3/value3. If this request already has any headers with that name, they are all replaced.
      Parameters:
      name1 -
      value1 -
      name2 -
      value2 -
      name3 -
      value3 -
      Returns:
      See Also:
      • Request.Builder.header(String, String)
    • headers

      public OkHttpRequest headers(Map<String,?> headers)
      Set http headers specified by the key/value entities from Map. If this request already has any headers with that name, they are all replaced.
      Parameters:
      headers -
      Returns:
      See Also:
      • Request.Builder.header(String, String)
    • headers

      public OkHttpRequest headers(okhttp3.Headers headers)
      Removes all headers on this builder and adds headers
      Parameters:
      headers -
      Returns:
      See Also:
      • Request.Builder.headers(Headers)
    • headers

      public OkHttpRequest headers(HttpHeaders headers)
      Removes all headers on this builder and adds headers
      Parameters:
      headers -
      Returns:
      See Also:
      • Request.Builder.headers(Headers)
    • addHeader

      @Deprecated public OkHttpRequest addHeader(String name, String value)
      Deprecated.
      no use case?
      Adds a header with 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.

    • removeHeader

      @Deprecated public OkHttpRequest removeHeader(String name)
      Deprecated.
      no use case?
      Parameters:
      name -
      Returns:
    • jsonBody

      public OkHttpRequest jsonBody(String json)
      Parameters:
      json -
      Returns:
    • jsonBody

      public OkHttpRequest jsonBody(Object obj)
      Parameters:
      obj -
      Returns:
    • formBody

      public OkHttpRequest formBody(Map<?,?> formBodyByMap)
      Parameters:
      formBodyByMap -
      Returns:
    • formBody

      public OkHttpRequest formBody(Object formBodyByEntity)
      Parameters:
      formBodyByEntity -
      Returns:
    • body

      @Deprecated public OkHttpRequest body(Map<?,?> formBodyByMap)
      Deprecated.
      replaced by formBody(Map).
      Parameters:
      formBodyByMap -
      Returns:
    • body

      @Deprecated public OkHttpRequest body(Object formBodyByEntity)
      Deprecated.
      replaced by formBody(Object).
      Parameters:
      formBodyByEntity -
      Returns:
    • body

      public OkHttpRequest body(okhttp3.RequestBody body)
      Parameters:
      body -
      Returns:
    • body

      public OkHttpRequest body(String content, @Nullable okhttp3.MediaType contentType)
      Parameters:
      content -
      contentType -
      Returns:
      See Also:
      • RequestBody.create(MediaType, String)
    • body

      public OkHttpRequest body(byte[] content, @Nullable okhttp3.MediaType contentType)
      Parameters:
      content -
      contentType -
      Returns:
      See Also:
      • RequestBody.create(MediaType, byte[])
    • body

      public OkHttpRequest body(byte[] content, int offset, int byteCount, @Nullable okhttp3.MediaType contentType)
      Parameters:
      content -
      offset -
      len -
      contentType -
      Returns:
      See Also:
      • RequestBody.create(MediaType, byte[], int, int)
    • body

      public OkHttpRequest body(File content, @Nullable okhttp3.MediaType contentType)
      Parameters:
      content -
      contentType -
      Returns:
    • get

      public okhttp3.Response get() throws IOException
      Throws:
      IOException
    • get

      public <T> T get(Class<T> resultClass) throws IOException
      Throws:
      IOException
    • post

      public okhttp3.Response post() throws IOException
      Throws:
      IOException
    • post

      public <T> T post(Class<T> resultClass) throws IOException
      Throws:
      IOException
    • put

      public okhttp3.Response put() throws IOException
      Throws:
      IOException
    • put

      public <T> T put(Class<T> resultClass) throws IOException
      Throws:
      IOException
    • patch

      public okhttp3.Response patch() throws IOException
      Throws:
      IOException
    • patch

      public <T> T patch(Class<T> resultClass) throws IOException
      Throws:
      IOException
    • delete

      public okhttp3.Response delete() throws IOException
      Throws:
      IOException
    • delete

      public <T> T delete(Class<T> resultClass) throws IOException
      Throws:
      IOException
    • head

      public okhttp3.Response head() throws IOException
      Throws:
      IOException
    • execute

      public okhttp3.Response execute(HttpMethod httpMethod) throws IOException
      Throws:
      IOException
    • execute

      public <T> T execute(Class<T> resultClass, HttpMethod httpMethod) throws IOException
      Throws:
      IOException
    • asyncGet

      public ContinuableFuture<okhttp3.Response> asyncGet()
    • asyncGet

      public ContinuableFuture<okhttp3.Response> asyncGet(Executor executor)
    • asyncGet

      public <T> ContinuableFuture<T> asyncGet(Class<T> resultClass)
    • asyncGet

      public <T> ContinuableFuture<T> asyncGet(Class<T> resultClass, Executor executor)
    • asyncPost

      public ContinuableFuture<okhttp3.Response> asyncPost()
    • asyncPost

      public ContinuableFuture<okhttp3.Response> asyncPost(Executor executor)
    • asyncPost

      public <T> ContinuableFuture<T> asyncPost(Class<T> resultClass)
    • asyncPost

      public <T> ContinuableFuture<T> asyncPost(Class<T> resultClass, Executor executor)
    • asyncPut

      public ContinuableFuture<okhttp3.Response> asyncPut()
    • asyncPut

      public ContinuableFuture<okhttp3.Response> asyncPut(Executor executor)
    • asyncPut

      public <T> ContinuableFuture<T> asyncPut(Class<T> resultClass)
    • asyncPut

      public <T> ContinuableFuture<T> asyncPut(Class<T> resultClass, Executor executor)
    • asyncPatch

      public ContinuableFuture<okhttp3.Response> asyncPatch()
    • asyncPatch

      public ContinuableFuture<okhttp3.Response> asyncPatch(Executor executor)
    • asyncPatch

      public <T> ContinuableFuture<T> asyncPatch(Class<T> resultClass)
    • asyncPatch

      public <T> ContinuableFuture<T> asyncPatch(Class<T> resultClass, Executor executor)
    • asyncDelete

      public ContinuableFuture<okhttp3.Response> asyncDelete()
    • asyncDelete

      public ContinuableFuture<okhttp3.Response> asyncDelete(Executor executor)
    • asyncDelete

      public <T> ContinuableFuture<T> asyncDelete(Class<T> resultClass)
    • asyncDelete

      public <T> ContinuableFuture<T> asyncDelete(Class<T> resultClass, Executor executor)
    • asyncHead

      public ContinuableFuture<okhttp3.Response> asyncHead()
    • asyncHead

      public ContinuableFuture<okhttp3.Response> asyncHead(Executor executor)
    • asyncExecute

      public ContinuableFuture<okhttp3.Response> asyncExecute(HttpMethod httpMethod)
    • asyncExecute

      public ContinuableFuture<okhttp3.Response> asyncExecute(HttpMethod httpMethod, Executor executor)
    • asyncExecute

      public <T> ContinuableFuture<T> asyncExecute(Class<T> resultClass, HttpMethod httpMethod)
    • asyncExecute

      public <T> ContinuableFuture<T> asyncExecute(Class<T> resultClass, HttpMethod httpMethod, Executor executor)