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

Blade 未结 2 757
93211656
93211656 剑圣 2023-03-22 17:55

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

2条回答
  • 2023-03-23 11:01

    参考如下写法,如果要在HttpUtil内增加超时时间,需要新增一个方法来配置connectTimeout

    image.png

    0 讨论(0)
  • 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<ApiResponse<InfoDTO>> getTaxPayer(@Query("shxydm") String code);


    0 讨论(0)
提交回复