How to set connection timeout with OkHttp
Tag : java , By : Arnaud Goudsmit
Date : March 29 2020, 07:55 AM
around this issue I am developing app using OkHttp library and my trouble is I cannot find how to set connection timeout and socket timeout. , You simply have to do this OkHttpClient client = new OkHttpClient();
client.setConnectTimeout(15, TimeUnit.SECONDS); // connect timeout
client.setReadTimeout(15, TimeUnit.SECONDS); // socket timeout
Request request = new Request.Builder().url(url).build();
Response response = client.newCall(request).execute();
client = new OkHttpClient.Builder()
.connectTimeout(10, TimeUnit.SECONDS)
.writeTimeout(10, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.build();
|
Using OKHttp, what is the difference between synchronous request in AsyncTask and OKhttp Asynchronous request?
Date : March 29 2020, 07:55 AM
this one helps. Quite a lot differs! Using AsyncTask for HTTP requests is pretty much one of the worst things you can do on Android. It's fraught with problems and gotchas that are best unconditionally avoided. For example, you cannot cancel a request during execution. The patterns of using AsyncTask also commonly leak a reference to an Activity, a cardinal sin of Android development.
|
OkHttp Request is not public in com.squareup.okhttp; cannot be accessed from outside package
Date : March 29 2020, 07:55 AM
it should still fix some issue Looks like the line compile files('libs/GlassVoice-xe22.jar') was causing the issue, I guess it contains an obsolete version of OkHttp because once I removed that line the code worked fine.
|
Okhttp timeout exception after 10 secs even though I have given 30 minutes as timeout.
Tag : java , By : user183842
Date : March 29 2020, 07:55 AM
wish of those help Here is the code OkHttpClient okHttpClient = new OkHttpClient().newBuilder()
.connectTimeout(60, TimeUnit.SECONDS)
.readTimeout(60, TimeUnit.SECONDS)
.writeTimeout(60, TimeUnit.SECONDS)
.build();
|
OkHttp connection timeout
Date : March 29 2020, 07:55 AM
|