Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set connection timeout in okhttp3?

Tags:

android

okhttp

How can I set time out in this code?

okhttp3.OkHttpClient client = new okhttp3.OkHttpClient();
okhttp3.Request request = new okhttp3.Request.Builder()
    .url(url)
    .get()
    .build();
Call call = client.newCall(request);
call.enqueue(callback);

Thanks.


1 Answers

 client = new OkHttpClient.Builder().connectTimeout(10, TimeUnit.SECONDS).build()
like image 95
Rene Ferrari Avatar answered Oct 24 '25 10:10

Rene Ferrari



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!