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

 

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *