如何在okhttp3中设置连接超时?

时间:2018-07-11 18:14:41

标签: android okhttp3

如何在此代码中设置超时时间?

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);

谢谢。

1 个答案:

答案 0 :(得分:2)

 client = new OkHttpClient.Builder().connectTimeout(10, TimeUnit.SECONDS).build()