OkHttp/Retrofit default timeout

后端 未结 5 1883
攒了一身酷
攒了一身酷 2020-12-23 13:47

I was wondering how many seconds should I set to my retrofit client.

  1. How many seconds should I use as default timeout?
  2. What is the default timeout fo
5条回答
  •  -上瘾入骨i
    2020-12-23 14:09

    1. It shouldn't take forever and not too short. IMHO, it should be between 10s and 30s.
    2. Default connect time out setting that Retrofit gives you (if you haven't specified http client explicitly) is 15 seconds.

    Source:

    OkHttpClient defaultClient() {   
        OkHttpClient client = new OkHttpClient();
        client.setConnectTimeout(15, TimeUnit.SECONDS);
        client.setReadTimeout(15, TimeUnit.SECONDS);
        client.setWriteTimeout(15, TimeUnit.SECONDS);
        return client;
    }
    
    1. I get this feeling Google is using 30 seconds. Not sure.

提交回复
热议问题