Home > Blockchain >  okhttp3 OkHttpClient setWriteTimeout equivalent
okhttp3 OkHttpClient setWriteTimeout equivalent

Time:07-03

I'm converting the okhttp.OkHttpClient.setWriteTimeout to okhttp3.OkHttpClient.setWriteTimeout but I'm getting undefined error even with okhttp3.OkHttpClient.writeTimeout.

It's weird, but writeTimeout is in the documentation, https://square.github.io/okhttp/3.x/okhttp/okhttp3/OkHttpClient.Builder.html#Builder--

Please help.

CodePudding user response:

writeTimeout() is part of okhttp3.OkHttpClient.Builder, not okhttp3.OkHttpClient. We could set the writeTimeout, along with proxy and any other configurations, with a single builder:

OkHttpClient client = new OkHttpClient.Builder()
        .proxy(proxy)
        .writeTimeout(1000, TimeUnit.MILLISECONDS)
        .readTimeout(1000, TimeUnit.MILLISECONDS)
        .build();
  • Related