我有這樣的:OkHttp如何監聽超時?
final OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url(someUrl)
.build();
Response response = client.newCall(request).execute();
我已經看過https://github.com/square/okhttp/wiki/Recipes#timeouts
我嘗試添加:
.connectTimeout(10, TimeUnit.SECONDS)
.writeTimeout(10, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
到OkHttpClient
建設者,但我沒有,甚至當我發現任何區別將超時數設置爲1秒。
是否有某種方法來監聽超時?如果超過此超時值,我應該發生什麼?