简体   繁体   中英

How to read / update connectTimeout & ReadTimeout in an OkHTTP Interceptor?

Why are connectTimeout & ReadTimeout available on OkHttpClient only? Is the "okhttp3.Request" not the right place?

Also,

  • How can I read / update the connectTimeout & ReadTimeout in an "okhttp3.Interceptor"?
  • Also, is it possible to know in an "okhttp3.Interceptor" that the call is a sync / async call?

You can do it in following way:

HTTP client 3:

OkHttpClient client = new OkHttpClient.Builder()
        .connectTimeout(5, TimeUnit.SECONDS)
        .writeTimeout(5, TimeUnit.SECONDS)
        .readTimeout(5, TimeUnit.SECONDS)
        .build();

HTTP client 2:

OkHttpClient client = new OkHttpClient();
    client.setConnectTimeout(5, TimeUnit.SECONDS);
    client.setReadTimeout(5, TimeUnit.SECONDS);
    client.setWriteTimeout(5, TimeUnit.SECONDS);
  1. Reference link okhttp3
  2. Reference link okhttp2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM