OkHttp Per Request Timeout Settting?

时间:2018-02-26 09:32:03

标签: java okhttp3

Click Here To show my issue,我只想设置每个请求超时和其他参数, 所以只需使用:

<!-- language: lang-java -->

 private static final OkHttpClient globalOkHttpClient = new OkHttpClient.Builder().build();
 private static final OkHttpClient otherOkHttpClient10 = globalOkHttpClient.newBuilder()
.connectTimeout(10,TimeUnit.SECONDS)
.build();
 private static final OkHttpClient otherOkHttpClient20 = globalOkHttpClient.newBuilder()
.connectTimeout(20,TimeUnit.SECONDS)
.build();

但是,这可能不会重复使用单个OkHttp实例?所以,我只是想问一下?如何设置OkHttpClient超时Per Request。 我的OkHttp3 maven依赖:

<!-- language: lang-xml -->

<dependency>
    <groupId>com.squareup.okhttp3</groupId>
    <artifactId>okhttp</artifactId>
    <version>3.9.0</version>
</dependency>

0 个答案:

没有答案