How to set connection timeout with OkHttp

OkHttp 用起來真的很方便。

官方網站:http://square.github.io/okhttp/


As of OkHttp3 can now do this through the Builder like so

client = new OkHttpClient.Builder()
        .connectTimeout(10, TimeUnit.SECONDS)
        .writeTimeout(10, TimeUnit.SECONDS)
        .readTimeout(30, TimeUnit.SECONDS)
        .build();

You can also view the recipe here

 

相關文章

寫留言

你的電子郵件位址並不會被公開。 必要欄位標記為 *