商业版自带blade-starter-http如何设置超时全局时间

Blade 未结 2 758
93211656
93211656 2023-03-22 17:55

HttpUtil请求如何设置全局超时时间

2条回答
  •  Jalena
    Jalena (楼主)
    2023-03-24 10:13

    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> getTaxPayer(@Query("shxydm") String code);


提交回复