Platform/Android

[Okhttp] timeout 설정

개랭갱깽스타 2021. 10. 8. 18:12

Connect Timeout

Read Timeout

Write Timeout

 

OkHttpClient.Builder builder = new OkHttpClient.Builder();
        HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
        loggingInterceptor.setLevel(VansBuildConfig.DEBUGGABLE ? HttpLoggingInterceptor.Level.BODY : HttpLoggingInterceptor.Level.NONE);
        builder.addInterceptor(loggingInterceptor);
        builder.connectTimeout(60, TimeUnit.SECONDS);
        builder.readTimeout(90, TimeUnit.SECONDS);   //받는(응답기다림)
        builder.writeTimeout(60, TimeUnit.SECONDS);   //보내는거(요청시간)
        if (interceptor != null) {
            builder.addInterceptor(interceptor);
}

 

참고.

https://square.github.io/okhttp/4.x/okhttp/okhttp3/-ok-http-client/-builder/read-timeout/

 

readTimeout - OkHttp - OkHttp

okhttp / okhttp3 / OkHttpClient / Builder / readTimeout readTimeout fun readTimeout(timeout:Long, unit:TimeUnit): Builder @IgnoreJRERequirement fun readTimeout(duration:Duration): Builder Sets the default read timeout for new connections. A value of 0 mean

square.github.io

https://effectivesquid.tistory.com/entry/Timeout%EC%97%90-%EA%B4%80%ED%95%9C-%EC%A0%95%EB%A6%AC

 

Timeout에 관한 정리

Connection Timeout 클라이언트가 서버측으로 connection을 맺길 원하지만 서버의 장애 상황으로 connection조차 맺어지지 못할 때 발생하는 timeout이다. Read Timeout 클라이언트와 서버가 connection은 맺어졌..

effectivesquid.tistory.com

 

반응형