HttpUtil请求如何设置全局超时时间
参考如下写法,如果要在HttpUtil内增加超时时间,需要新增一个方法来配置connectTimeout
retrofit2 + okhttp3
比这个好用太多了!!!!
@Bean
public Retrofit initRetrofit(){
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC);
OkHttpClient client = new OkHttpClient.Builder()
.addInterceptor(loggingInterceptor)
//.addInterceptor(new TokenInterceptor(stringRedisTemplate, properties))
.connectTimeout(timeout, TimeUnit.SECONDS)
.writeTimeout(timeout, TimeUnit.SECONDS)
.readTimeout(timeout, TimeUnit.SECONDS)
.build();
return new Retrofit.Builder()
.baseUrl(host)
.client(client)
.addConverterFactory(JacksonConverterFactory.create(JsonUtil.getInstance()))
.addCallAdapterFactory(RxJava3CallAdapterFactory.create())
.build();
}
@GET("/xxx/xx/xx/aaa")
Call<ApiResponse<InfoDTO>> getTaxPayer(@Query("shxydm") String code);
扫一扫访问 Blade技术社区 移动端