okhttp禁止重定向

followRedirects(false)

    private OkHttpClient getOkHttpClient() {
        if (client == null) {
            HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
            httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
            client = new OkHttpClient.Builder()
                    .writeTimeout(20, TimeUnit.SECONDS)
                    .connectTimeout(5, TimeUnit.SECONDS)
                    .readTimeout(30, TimeUnit.SECONDS)
                    .addInterceptor(httpLoggingInterceptor)
                    .followRedirects(false)
                    .build();
        }
        return client;
    }
posted @ 2020-10-19 01:01  amberbar  阅读(1234)  评论(0编辑  收藏  举报